Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
I am making a function to print the lyrics of 99 bottles song. When I use the console.log, it works but it doesn't work when I use 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.");

}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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 += "\n\n";
    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.\n\n"
  );

  return lyrics;
}

const response = beer();
console.log(response);

You just need to append all the lyrics to the string and at the end just return from the function.

I hope this will answer the question

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda