我正在制作一个功能来打印99瓶歌曲的歌词。当我使用控制台.log时,它可以工作,但当我使用 return 时它不起作用


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);

您只需要将所有歌词附加到字符串中,并在最后从函数返回。

我希望这将回答这个问题

相关内容

  • 没有找到相关文章

最新更新