Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Change the program so that instead of using a procedure, it includes a function

ID: 3621118 • Letter: C

Question

Change the program so that instead of using a procedure, it includes a function that returns a string. The new singsong function should test beers to see if it is greater than zero. If so it should print the lyrics and then return the string Later. If it is not greater than zero, it should return the string Sorry. Have your main program print out this return value. Hence, if a user enters zero or a negative number in answer to the question How many bottles? The response will be Sorry. If the user enters a positive number greater than zero, the lyrics of the song will be printed followed by Later.
// Variables
var count; // numeric

// Funtions
function singsong(beers /*numeric*/) // void
{   
      while ((beers > 0))
       {
document.write(beers);
document.writeln(“ bottles of beer on the wall,”);
document.write(beers);
document.writeln((“ bottles of beer,”);
document.write(“Take one down. Pass it around.”);
beers = beers – 1;
document.write(beers);
document.writeln(“ bottles of beer on the wall,”);
document.writeln(“ “);
         }
}
// Main Program
count = parseFloat(prompt(How many bottles?”,0));
singsong(count)
document.writeln(“Later…”);

Output with 2 bottles like it is:

2.0 bottles of beer on the wall,

2.0 bottles of beer.

Take one down. Pass it around

1.0 bottles of beer on the wall.

Output with 2 bottles like it is:

1.0 bottles of beer on the wall,

1.0 bottles of beer.

Take one down. Pass it around

0.0 bottles of beer on the wall.

Later....

Explanation / Answer

Dear... // Variables var count; // numeric // Funtions function singsong(beers ) // void { while (beers > 1) { document.write(beers); document.writeln(" bottles of beer on the wall,
"); document.write(beers); document.writeln(" bottles of beer.
"); document.write("Take one down. Pass it around.
"); beers = beers - 1; } document.writeln(beers ," bottle of beer on the wall,
"); document.writeln(beers ," bottle of beer.
"); document.write("Take one down. Pass it around.
"); } // Main Program count = prompt("How many bottles?",0); if(count
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote