Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda