function beer() {
var n = 99;
while (n>1) {
var m = n-1;
console.log((n + "bottles of beer on the wall," + n + "bottles of beer. Take one down and pass it around," + m + "bottles of beer on the wall."));
n--;
}
console.log("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.");
}
function beer() {
var n = 99;
var lyrics = "";
while (n > 1) {
var m = n - 1;
lyrics +=
n +
"bottles of beer on the wall," +
n +
"bottles of beer. Take one down and pass it around," +
m +
"bottles of beer on the wall.";
lyrics += "nn";
n--;
}
lyrics+=(
"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.nn"
);
return lyrics;
}
const response = beer();
console.log(response);
您只需要将所有歌词附加到字符串中,并在最后从函数返回。
我希望这将回答这个问题