I am trying to write code in JavaScript to get the same output as shown in this link http://www.99-bottles-of-beer.net/lyrics.html I guess I need to learn more about while loop. I tried to change the code many times like 10 maybe and Now I got frustrated.
My Code:-
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();
Make sure you handle, what to be looped. If you want to output something repeatedly, keep corresponding code in inside loop body. Also make sure loop condition is modifiable while loop is running. At somepoint loop should terminate. I have kept a running version of code here for ref. 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();