48.6k views
4 votes
Tiffany is writing a program to help manage a bake sale. She writes the following code which prompts the user to enter the total number of items a person is buying and then a loop repeatedly prompts for the cost of each item. She wrote the code but there is a problem: it runs in an infinite loop. How can Tiffany change her code so it doesn't loop forever? 0 var numItems = promptNum("How many items?"); 1 var total = 0;

1 Answer

2 votes

Answer:

Add after line 3:

numItems = numItems - 1;

Step-by-step explanation:

The complete code of Tiffany should be provided in question is:

line 0 -- var numItems = promptNum("How many items?");

line 1-- var total = 0;

line 2-- while (numItems > 0){

line 3-- total = total + promptNum("Enter next item price");

line4-- }

line 5-- console.log("The total is" + total);

User VArDo
by
5.0k points