Question

In: Computer Science

JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include...

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.

Solutions

Expert Solution

/* 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:


Related Solutions

JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include...
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: Create a program that simulates tossing a coin. This program should be titled flippingacoin.js and will require you...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function,...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var triangle.js Write a program that is required to use nested loops to generate a triangle as shown in the sample run below. The program should begin by prompting the user...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function,...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var Name: coinflip.js For this program you will have two functions, one called main and the second called flip. This program is also required the use of a loop construct. Write...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function,...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var Name: cookout.js 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...
Using HTML and JAVASCRIPT Create a Content area on the main entry page will include inputs...
Using HTML and JAVASCRIPT Create a Content area on the main entry page will include inputs for customer entry for the following: Entry field (with labeling) for the Customer's name Entry field (with labeling) for the Customer's email address Entry field (with labeling) for which room the customer is planning on painting Entry field (with labeling) for the width of the room Entry field (with labeling) for the length of the room Entry field (with labeling) using a colour box...
You will be writing the function definition and the main function with the function call. Be...
You will be writing the function definition and the main function with the function call. Be sure to write the function definition below the main function. The function prototype has been provided, you may add the prototype to you answer. You do not need to add the preprocessor directives like #include<stdio.h>. Write the function definition for UpdateGrade . The function will take two arguments, a double called originalGrade a pointer to a double called newGradePtr. This function will have a...
The main tasks of this C++ programming assignment include implementing a transformation matrix and a view/projection...
The main tasks of this C++ programming assignment include implementing a transformation matrix and a view/projection matrix. Giving three 3D points v0(2.0, 0.0, −2.0), v1(0.0, 2.0, −2.0), v2(−2.0, 0.0, −2.0),you are required to transform these points to the camera/view/monitor coordinates system, and draw a lined triangle based on them get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar): using the giving parameter, build a projection matrix, and return it. Here is what I have so far. Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio,...
only JAVA code /** Create a method as instructed below and then call it appropriately. */...
only JAVA code /** Create a method as instructed below and then call it appropriately. */ import java.util.Scanner; public class MoreBankCharges { //Constant declarations for base fee and per check fees //Class scope so constants are accessible by all methods static final double BASE_FEE = 10.0; static final double LESS_THAN_20_FEE = 0.10; static final double TWENTY_TO_THIRTYNINE_FEE = 0.08; static final double FORTY_TO_FIFTYNINE_FEE = 0.06; static final double SIXTY_OR_MORE_FEE = 0.04; public static void main(String[] args) { //Variable declarations int numChecks;...
/** Create a method as instructed below and then call it appropriately. */ import java.util.Scanner; public...
/** Create a method as instructed below and then call it appropriately. */ import java.util.Scanner; public class BankCharges { public static void main(String[] args) { //Variable declarations int numChecks; double perCheckFee; double totalFee; double totalFeesAllAccounts = 0; //accumulator int numAccounts;    //Constant declarations for base fee and per check fees final double BASE_FEE = 10.0; final double LESS_THAN_20_FEE = 0.10; final double TWENTY_TO_THIRTYNINE_FEE = 0.08; final double FORTY_TO_FIFTYNINE_FEE = 0.06; final double SIXTY_OR_MORE_FEE = 0.04;    // Create a Scanner...
For this assignment you need to create a ToDo list using Javascript, along with HTML and...
For this assignment you need to create a ToDo list using Javascript, along with HTML and CSS. Begin by creating a HTML page called todo.html. Then create a Javascript file called todo.js and link it in to the HTML page using a script tag. All Javascript for the assignment must be in the separate file. (For CSS, feel free to include styles in a style block at the top of the HTML page, or to link in CSS from a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT