In: Computer Science
JavaScript Programming Assignment
PLEASE NOTE: You must create and call a main function, and if instructed include additional functions called by the main. Make sure to use ES6 style of keywords => instead of the older function and for local scope variables use the keyword let and not a keyword var. Make sure to follow the requirements and recheck before submitting.
PROJECT GOAL:
Assume that hot dogs come in packages of 10, and hot dog buns come in packages of 8. Write a program called cookout.js, 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 will prompt for the number of people attending the cookout and as how many hot dogs each guest will eat. 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.
/* 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? "));
// input of number of hot dogs each guest will
eat
let num_hotdogs = parseInt(readline.question("Enter
the number of hotdogs each guest will eat? "));
// 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 the total hotdogs
let total_hotdogs = num_people * num_hotdogs;
// calculate hotdogs packages
if(total_hotdogs%hotdogs_per_package == 0)
hotdog_packages =
parseInt(total_hotdogs/hotdogs_per_package);
else
hotdog_packages =
parseInt(total_hotdogs/hotdogs_per_package)+1;
// calculate hotdog buns packages
if(total_hotdogs%hotdog_buns_per_package == 0)
hotdog_buns_packages =
parseInt(total_hotdogs/hotdog_buns_per_package);
else
hotdog_buns_packages =
parseInt(total_hotdogs/hotdog_buns_per_package)+1;
// calculate hotdogs leftovers
let hotdog_leftover =
(hotdog_packages*hotdogs_per_package) - total_hotdogs;
// calculate hotdog buns leftovers
let hotdog_buns_leftover =
(hotdog_buns_packages*hotdog_buns_per_package)-total_hotdogs;
// 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: