嗨,我已經做了99瓶啤酒歌,但我的代碼似乎並沒有工作我不知道,我無法弄清楚。我真的需要一些幫助,看看我哪裏出錯或有人告訴我哪裏出錯。我想要如果陳述,或者如果有不同的方式來做到這一點,但我需要設置它是如何不知道如何解決它,請幫助。 在此先感謝。「99瓶啤酒在牆上」的代碼不工作純js。如果聲明和while循環
這是我的JavaScript。
var bottles = 99
bottle = "bottles";
text = "";
var output = document.getElementById('output');
while (bottles > 0) {
if (bottles == 1) {
bottle = "bottle";
text = "<p>" + bottles + " " + bottle + " of beer on the wall, " + bottles + " " + bottle + " of beer. <br/>";
bottles--;
output.innerHTML += text;
}
if (bottles == 0) {
bottles = "no more";
text += "Take one down and pass it around, " + bottles + " bottles of beer on the wall. </p>"
output.innerHTML += text;
}
output.innerHTML += "<p> No more bottles of beer on the wall, no more bottles of beer. <br/> Go to the store and buy some more, 99 bottles of beer on the wall.</p>"
這是我的HTML。
<title>My Title</title>
<script src="javascript.js"></script>
<div style="text-align: center;">
<h1>99 Bottles of Beer Song</h1>
<div id="output"></div>
我也有小提琴。 http://jsfiddle.net/Matt1990/1wg16qr5/46/
你能提供的jsfiddle? – 2014-09-06 09:45:58
我只是對不起 – Matthew 2014-09-06 09:46:43
從哪裏開始?.....沒有事件啓動您的應用程序。你的變量聲明中的語法錯誤... – 2014-09-06 09:49:02