2016-08-01 88 views
0

我有點麻煩,寫文本的唯一行是document.write(「房間是」+牆+「平方英尺」+ BR);在我進入提示窗口之後,沒有別的東西出現,我是否做錯了什麼?Javascript代碼document.write

<!DOCTYPE html> 
<html> 
<body> 
<script type="text/javascript"> 
var BR = "<br />"; 
var galPaint = 100; 
var galNeeded; 
var length; 
var width; 
length = prompt("enter legnth of room in inches"); 
width = prompt("enter width of room in inches"); 
var perimeter = (Number(length)+Number(width))*2; 
var walls = (perimeter*96)/Math.pow(12,2); 
document.write("The room is"+ walls +"square feet"+ BR); 
var doors; 
var windows; 
doors = prompt("Enter Number of doors"); 
windows = prompt("enter number of windows"); 
var sqfWindow = (Number(doors)*14); 
var sqftDoor = (Number(windows)*20); 
var totalSqft = (walls-(sqftWindow + sqftDoor)); 
galNeeded = (totalSqft/galpaint); 
document.write("You need" + galNeeded + "gallons of paint" + BR); 
</script> 

</body> 
</html> 
+0

注意:'document.write'永遠不會(幾乎沒有)好的做法 –

回答

0

這裏亞去,https://jsfiddle.net/4omvboz8/1/

你在你的代碼:)有幾個錯別字,固定的盪滌變量等。加一個div元素,並寫信給那,而不是文件。寫..

<!DOCTYPE html> 
<html> 
<body> 
    <div id="textArea"></div> 
</body> 

<script type="text/javascript"> 
var galPaint = 100, galNeeded, length, width, 
perimeter, walls, doors, windows, sqfWindow, 
sqftDoor, totalSqft, 
textarea = document.getElementById("textArea"); 

length = prompt("enter legnth of room in inches"); 
width = prompt("enter width of room in inches"); 

perimeter = (Number(length)+Number(width))*2; 
walls = (perimeter*96)/Math.pow(12,2); 

textarea.innerHTML += "The room is "+ walls +" square feet <br />"; 

doors = prompt("Enter Number of doors"); 
windows = prompt("Enter number of windows"); 

sqftDoor = (Number(doors)*14); 
sqftWindow = (Number(windows)*20); 
totalSqft = (walls-(sqftWindow + sqftDoor)); 
galNeeded = (totalSqft/galPaint); 

textarea.innerHTML += "You need " + galNeeded + " gallons of paint <br />"; 
</script> 
</html> 
+0

非常感謝你的幫助 –