As a JavaScript beginner, I'm puzzled about why the first loop result shows an "undefined" variable while the rest include "bottles." The goal is to output a statement from 99 to 1.
Below is a snippet of the code:
/*
* Programming Quiz: 99 Bottles of Juice (4-2)
*
* Use the following `while` loop to write out the song "99 bottles of juice".
* Log your lyrics to the console.
*
* Note
* - Each line of the lyrics needs to be logged on the same line.
* - The pluralization of the word "bottle" changes from "2 bottles" to "1 bottle" to "0 bottles".
*/
var num = 99;
let statementSplit = ((num + " " + bottles + " of juice on the wall! " + num + " " + bottles + " of juice! Take one down, pass it around... "));
while (num > 0) {
var bottles = (num > 1 ? "bottles" : "bottle");
statementSplit += ((num + " " + bottles + " of juice on the wall! " + num + " " + bottles + " of juice! Take one down, pass it around... "));
// var statementSplit=((num+" "+bottles+" of juice on the wall! " + num + " "+ bottles+" of juice! Take one down, pass it around... "));
num = num - 1;
}
console.log(statementSplit);