I’m trying of making the lyrics of 99 Bottles of Beer
This is what I’ve got on the last line:
1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around,
no more bottle of beer on the wall.
How can I put another line said(With the N capital letter)
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
var beer = 99;
while (beer >= 0) {
var words = "bottles";
if (beer === 1) {
words = "bottle";
}
console.log(beer + " " + words + " of beer on the wall, " + beer + " " + words + " of beer.Take one down and pass it around, ");
beer--;
if (beer === 1) {
words = "bottle";
}
if (beer === 0) {
beer = "no more";
}
console.log(beer + " " + words + " of beer on the wall.");
}
3
Answers
You can modify your code to add the special case for "No more bottles" after the loop.
You can also add the console.log under the if loop
See the other answers for extensions of your existing code
Here is a rewrite as DRY as I can get it.
Here is another for fun and education