Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!