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

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...
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...
Answer the questions on Hess's Law listed below. Please note that you must include units throughout...
Answer the questions on Hess's Law listed below. Please note that you must include units throughout all of your calculations and provide your answer in scientific notation to the correct number of significant digits. Click on the red flags to the left to review content on scientific notation and significant digits. Question 1 Iron is made from a reaction of iron oxide with carbon monoxide in the following reaction: Fe2O3(s) + 3 CO(g) → 2 Fe(s) + 3 CO2(g) Using...
For this assignment, you will be describing hemostasis and associated disorders. Your assignment must include the...
For this assignment, you will be describing hemostasis and associated disorders. Your assignment must include the following: 1. Description of how the blood system works to stop bleeding (hemostasis). 2. Summary of the clotting cascade including a description of the intrinsic, extrinsic, and common pathways, and an overview of clotting factors. 3. Discussion of how 2 different anticoagulant medications work to stop clotting.
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must have elements as follow: first ( value passed will be String ) last ( value passed will be String ) age ( value passed will be Numeric ) The constructor will assign the values for the three elements and should use the "this" keyword Create a function, using "printObject" as the identifier printObject: This function will have three input parameters: allNames , sortType, message...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT