Question

Hello: Need help with this program. In JavaScript please // Assume hot dogs come in packages...

Hello:

Need help with this program. In JavaScript please

// Assume hot dogs come in packages of 10, and hot dog buns come in packages of 8.

// Write a program that calculates the number of packages of hot dogs and the

// number of packages of hot dog buns needed for a cookout, with the minimum amount

// of leftovers. The program should ask the user for the number of people attending

// the cookout. Assume each person will eat 1 hotdog.

//

// The program should display the following details:

//

// The minimum number of packages of hot dogs required

// The minimum number of packages of hot dog buns required

// The number of hot dogs that will be left over

// The number of hot dog buns that will be left over

//

// Hint: You might want to use the % operator in one of your calculation

//

function packagesNeeded(numberOfPeople, itemsPerPack) {

This code does not work:

var minPackageHotDog = Math.ceil(numberOfPeople/10);

              var minPackageHotDogBun = Math.ceil(numberOfPeople/8);

console.log("The minimum number of packages of hot dogs required: " + minPackageHotDog);
          
console.log("The minimum number of packages of hot dog buns required: " + minPackageHotDogBun);

--

var minLeftOverHotDogs = (10 * minPackageHotDog - numberOfPeople);

var minLeftOverHotDogBuns = (8 * minLeftOverHotDogBun - numberOfPeople);

console.log('The number of hot dogs that will be left over: ' + minLeftOverHotDog);

console.log('The number of hot dog buns that will be left over: ' + minLeftOverHotDogBun);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/* Javascript program that calculates the number of packages of hot dogs
and the number of packages of hot dog buns needed for a cookout, with the minimum amount of leftovers*/

let readline = require('readline-sync'); // module for taking input

var main = () =>{
  
   //input of the number of people attending the cookout
   let num_people = parseInt(readline.question("Enter number of people attending the cookout? "));
  
   // variables to set the number of hotdogs per package and hotdog buns per package
   let hotdogs_per_package = 10;
   let hotdog_buns_per_package = 8;
  
   let hotdog_packages,hotdog_buns_packages;
  
// calculate hotdogs packages
   if(num_people%hotdogs_per_package == 0)
       hotdog_packages = parseInt(num_people/hotdogs_per_package);
   else
       hotdog_packages = parseInt(num_people/hotdogs_per_package)+1;
  
   // calculate hotdog buns packages
   if(num_people%hotdog_buns_per_package == 0)
       hotdog_buns_packages = parseInt(num_people/hotdog_buns_per_package);
   else
       hotdog_buns_packages = parseInt(num_people/hotdog_buns_per_package)+1;

   // calculate hotdogs leftovers
   let hotdog_leftover = (hotdog_packages*hotdogs_per_package) - num_people;
   // calculate hotdog buns leftovers
   let hotdog_buns_leftover = (hotdog_buns_packages*hotdog_buns_per_package) - num_people;
  
   // output
   console.log("The minimum number of packages of hot dogs required : "+hotdog_packages);
   console.log("The minimum number of packages of hot dog buns required : "+hotdog_buns_packages);
   console.log("The number of hot dogs that will be left over : "+hotdog_leftover);
   console.log("The number of hot dog buns that will be left over : "+hotdog_buns_leftover);
}

// call the main function
main()

//end of program

Output:

Add a comment
Know the answer?
Add Answer to:
Hello: Need help with this program. In JavaScript please // Assume hot dogs come in packages...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The question in the textbook is as follows: Hot Dog Cookout Calculator Assume that hot dogs...

    The question in the textbook is as follows: Hot Dog Cookout Calculator Assume that hot dogs come in packages of 10, and hot dog buns come in packages of 8. Design a modular program that calculates the number of packages of hot dogs and the number of packages of hot dog buns needed for a cookout, with the minimum amount of leftovers. The program should ask the user for the number of people attending the cookout, and the number of...

  • In python coding please with proper indentation, comments, good variable initializations, questions asking for the parameters...

    In python coding please with proper indentation, comments, good variable initializations, questions asking for the parameters of the code and output display with explanation.: Assume that hot dogs come in packages of 20, and hot dog buns come in packages of 8. Design a modular program that calculates the number of packages of hot dogs and the number of packages of hot dog buns needed for a cookout, with the minimum amount of leftovers. The program should ask the user...

  • You decide to have hot dogs for dinner. In the grocery store, you find that buns...

    You decide to have hot dogs for dinner. In the grocery store, you find that buns come only in packages of 12, whereas the hot dogs come in packages of 8. How can your purchases lead to having no buns or hot dogs left over? (How does this problem fit in with chemical bonding and other parts of this chapter?)

  • This is an external javascript file // Problem 1:   Declare the variables num1, num2, ans1, //  ...

    This is an external javascript file // Problem 1:   Declare the variables num1, num2, ans1, //               greet1, greet2. Then initialize them to //               hold the values 1, 2, 0, "Hello", and //               "World", respectively. var num1 = 1; var num2 = 2; var ans1 = 0; var greet1 = "Hello"; var greet2 = "World"; // Problem 1a:   Display the values stored in the previous //               variables in the...

  • I need HELP to get the code to do these function: If I keep clicking "Generate"...

    I need HELP to get the code to do these function: If I keep clicking "Generate" multiple times, the list keeps on getting bigger. The number of rows should always be equal to the number of columns. Also make the code to show both table at the same time? Here is the code I got some far : Code: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Testing</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> </head> <style> td...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • Please, I need help with program c++. This is a chutes and ladders program. The code...

    Please, I need help with program c++. This is a chutes and ladders program. The code must be a novel code to the specifications of the problem statement. Thank you very much. Assignment Overview This program will implement a variation of the game “chutes and ladders” or “snakes and ladders:” https://en.wikipedia.org/wiki/Snakes_and_Ladders#Gameplay. Just like in the original game, landing on certain squares will jump the player ahead or behind. In this case, you are trying to reach to bottom of the...

  • LAB PROMPT: Lab 07 Hello future bakers and artisans of the fine gourmet. You love to...

    LAB PROMPT: Lab 07 Hello future bakers and artisans of the fine gourmet. You love to throw parties, and what goes better at a party than cake! The problem is that you only have enough flour to bake a limited number of cakes. In this lab, you will write a small program to figure out if you have enough flour to bake the number of cakes needed for the people attending. Step 1 - using final At the top of...

  • hello there, i have to implement this on java processing. can someone please help me regarding...

    hello there, i have to implement this on java processing. can someone please help me regarding that? thanks War is the name of a popular children’s card game. There are many variants. After playing War with a friend for over an hour, they argue that this game must never end . However! You are convinced that it will end. As a budding computer scientist, you decide to build a simulator to find out for sure! You will implement the logic...

  • Veternarian Nursing . Tutoring please. Need help. Thanks ASSIGNMENTY READING DRUG LABELS AND PRESCRIPTIONS Name ADMINISTERING...

    Veternarian Nursing . Tutoring please. Need help. Thanks ASSIGNMENTY READING DRUG LABELS AND PRESCRIPTIONS Name ADMINISTERING FOR EACH OF THE FOLLOW LOULATE THE DONE AND WEIGHT OF DRUG YOU AR INDICATED FOR EACH OF THE FOLLOWING FOR THE PATIENT ROVIDED. PLEASE HIGHLIGHT YOUR ANSWERS USE THE CONCENTRATION INDICATED ON THE LABEL PATIENT CONDITION PHENOBARBITAL TABLETS USD 15 mg, 14 Ta 15 b. dog Idiopathi epilepsy 2 mg/kg PO BID 1b The veterinarian asks you to fill a prescription for this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT