我是编程新手,我正在学习如何做JavaScript。我书中的问题说我必须在我的html页面中使用循环编写程序,但它们都在同一行。我不能让我的程序下线,我使用document.write,因为它在html中使用JavaScript
这是程序:
<html>
<body>
<script>
var sheepCounted = 0;
while (sheepCounted < 10) {
document.write("I have counted " + sheepCounted + " sheep!");
sheepCounted++;
}
</script>
</body>
</html>
但所有返回是:
I have counted 0 sheep!I have counted 1 sheep!I have counted 2 sheep!I have counted 3 sheep!I have counted 4 sheep!I have counted 5 sheep!I have counted 6 sheep!I have counted 7 sheep!I have counted 8 sheep!I have counted 9 sheep!
(全部在一行上)
我也对这个代码 问题 我的第一个正确的HTML页面
<body>
<h1>Hello</h1>
<p>My First web page.</p>
<script>
var name = "Nick ";
document.write("Hello, " + name);
if (name.length > 7) {
document.write("Wow, you have a REALLY long name!");
}
else {
document.write("Your name isnt very long")
}
</script>
</body>
</html>
请帮助我!!!!!
追加''
羊后'使用文件撰写!'。 FWIW,'document.write()'是一种向浏览器窗口输出数据的不好方法。铭记未来。 – 2015-02-08 22:09:58
我是怎么卖的? – 2015-02-08 22:13:00
我应该怎么做? – 2015-02-08 22:13:25