175k views
1 vote
To plan a pizza party, one may want to order enough pizza for everyone. Use the slicesInPizza, slicesPerPerson, and totalGuests variables to compute the total number of pizzas needed to feed all the guests and store the result in totalPizzas. The total may have a decimal place.

1 var slicesInPizza = 8; // Code tested with values: 8 and 12
2 var slices PerPerson = 4; // Code tested with values: 4 and 5
3 var totalI Persons = 12; // Code tested with values: 12 and 10
4
5 var pizzasNeeded = 0;

User Dhpratik
by
4.6k points

1 Answer

1 vote

Answer:

Step-by-step explanation:

The following code was written in Javascript. It asks the user to enter the values for each of the variables and saves it to them. Then it uses those values to calculate the total number of pizzas needed to feed everyone at the party. Finally, it prints out the total to the screen as an alert. Both test cases were used and the outputs can be seen in the attached images below.

var slicesPerPizza = window.prompt("How many slices per pizza?");

var slicesPerPerson = window.prompt("How many slices per person?");

var totalPersons = window.prompt("How many total people will attend?");

var pizzasNeeded = Math.round((slicesPerPerson * totalPersons) / slicesPerPizza)

alert(`You need a total of ${pizzasNeeded} pizzas.`)

To plan a pizza party, one may want to order enough pizza for everyone. Use the slicesInPizza-example-1
To plan a pizza party, one may want to order enough pizza for everyone. Use the slicesInPizza-example-2
User Merwann Selmani
by
5.3k points