我遇到了一点麻烦,写这篇文章的唯一一行是document.write("房间是" +墙+"平方英尺" + BR) ;在我进入门窗进入提示后,没有别的东西出现我做错了什么?
<!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 :(得分:0)
在这里,你去https://jsfiddle.net/4omvboz8/1/
你的代码中有一些拼写错误:),修复了那些并清理了变量等。添加了一个div元素并写入了而不是document.write ..
<!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>