纯瓶中的99瓶歌曲代码

时间:2014-08-23 05:35:43

标签: javascript

有些人可以帮我告诉我我的代码在哪里出错了。我已经工作了一段时间,但我仍然卡住请帮忙。到目前为止这是我的代码。感谢您的帮助。

这是我的javascript

var bottles; 
var beerNum = 99;

// This program will count to 99 for us

// Set up a counter variable, and start it on zero (good place to start)
var counter = 0;

// While loop
while (counter < 99) {

    // This line increments (or adds 1) to our counter each time the loop goes around.
    counter--;

    // This line finds the HTML element with an ID of "output" and puts the value of our counter in it, followed by a line break <br />
    // The += operator takes what's already stored and appends our new value to it
    document.getElementById('output').innerHTML += counter + "<br />";

}
if (bottles = beerNum){ 
    document.getElementById('output')>innerHTML += bottles + beerNum + "of beer on the wall";
}

这是我的HTML。

<p id="output"></p>

我有一个小提琴陪伴它

http://jsfiddle.net/Matt1990/X4UHD/39/

1 个答案:

答案 0 :(得分:0)

这可能对你有所帮助:

for(var i=99; i>0; i--){
    document.getElementById("output").innerHTML += i + "Bottles on the wall take one down, pass it around." + "<br>";
}

http://jsfiddle.net/a0knrxzs/

编辑: 我们不需要while循环,for循环只会在不再大于0时停止。While循环用于在更改某些内容后停止循环。