无法获得输出
Unable to get output
我正在尝试在 JavaScript 中编写代码以获得与此 link http://www.99-bottles-of-beer.net/lyrics.html 中所示相同的输出
我想我需要更多地了解 while 循环。我尝试多次更改代码,例如 10 次,现在我很沮丧。
我的代码:-
function beer() {
var count = 99;
while (count >= 0) {
var output = count + " bottles of beer on the wall, " + count +
" bottles of beer. Take one down and pass it around, " + (count-1) + " bottles of beer on the wall.";
}
count--;
console.log(output);
}
beer();
确保您处理要循环的内容。如果你想重复输出一些东西,在循环体内保留相应的代码。
还要确保循环条件是可修改的,而循环是 运行。在某个时候循环应该终止。
我在这里保留了一个 运行 版本的代码以供参考。 https://jsfiddle.net/a2qdk9t8/
function beer() {
var count = 99;
while (count >= 0) {
var output = count + " bottles of beer on the wall, " + count +
" bottles of beer. Take one down and pass it around, " + (count-1) + " bottles of beer on the wall.";
count--;
console.log(output);
}
}
beer();
我正在尝试在 JavaScript 中编写代码以获得与此 link http://www.99-bottles-of-beer.net/lyrics.html 中所示相同的输出 我想我需要更多地了解 while 循环。我尝试多次更改代码,例如 10 次,现在我很沮丧。
我的代码:-
function beer() {
var count = 99;
while (count >= 0) {
var output = count + " bottles of beer on the wall, " + count +
" bottles of beer. Take one down and pass it around, " + (count-1) + " bottles of beer on the wall.";
}
count--;
console.log(output);
}
beer();
确保您处理要循环的内容。如果你想重复输出一些东西,在循环体内保留相应的代码。 还要确保循环条件是可修改的,而循环是 运行。在某个时候循环应该终止。 我在这里保留了一个 运行 版本的代码以供参考。 https://jsfiddle.net/a2qdk9t8/
function beer() {
var count = 99;
while (count >= 0) {
var output = count + " bottles of beer on the wall, " + count +
" bottles of beer. Take one down and pass it around, " + (count-1) + " bottles of beer on the wall.";
count--;
console.log(output);
}
}
beer();