我是編程新手,我正在學習如何做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