1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Arte-miy333 [17]
3 years ago
15

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;
2 while (numItems > 0){
3 total = total + promptNum("Enter next item price");
4 }
5 console.log("The total is" + total);
Add after line 3: numItems = numItems - 1;

What value will be displaye
Computers and Technology
1 answer:
PtichkaEL [24]3 years ago
8 0

Answer:

Explanation:

the answer is also in the question. The loop is used to control the number of  program execution. So in order not to run forever, the loop should be included inside the loop brackets. Then you can restructure the code as done below.

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

var total = 0;

var itemPrice=0;

while (numItems > 0){

itemPrice = promptNum("Enter next item price");

total = total + itemPrice;

numItems = numItems - 1;

}

console.log("The total is" + total);

The value to be displayed will be the total of the item prices inputted.

You might be interested in
Why can't cruise control work under 25 mph?
beks73 [17]
<span>At lower speeds modulating speeds is a must for safety. I would be hard pressed to find a place in town you could drive 25 mph for an extended time. Also, plan on a lot of shifting at lower speeds. That completely negates using the cruise on a manual and really puts the auto in the hunting mode. I would think it safer that you move the selector into a lower gear to get some engine braking at say, 25 mph which would make it easier to sustain the speed rather then use the cruise.

Brainliest please?</span>
4 0
3 years ago
Advantages of desktop publishing over traditional methods include       
Licemer1 [7]
From what my teacher taught us it would be c.
6 0
3 years ago
A hacker tries to compromise your system by submitting script into a field in a web application that is then stored as data in t
sdas [7]
D cross-site scripting
3 0
3 years ago
Read 2 more answers
I need help please, thank you
swat32
Select all answers except computers, xbox, playstation 5, and mobile!

hope this helps!
8 0
2 years ago
Pets can provide good practice for photographing wildlife. True or false
Sedaia [141]
Especially when you get them like sniffing flowers or wrestling with other dogs so true
5 0
3 years ago
Read 2 more answers
Other questions:
  • HEY DO U LIKE TRAINS!
    7·1 answer
  • Wireless attacks avoid the access points to limit detection. <br> a. True <br> b. False
    9·1 answer
  • What is the main goal of computer generated by digitalization
    8·1 answer
  • Do you watch markiplier?
    13·2 answers
  • The ________ identifies staff reaction and response times as well as inefficiencies or previously unidentified vulnerabilities.
    5·1 answer
  • 8. Given the array String[] words, which already contains 1 or more values, write a block of code which counts and returns the n
    7·1 answer
  • ¿Por qué es importante usar adecuadamente el celular?
    5·1 answer
  • This tag is used to change the appearance of your text on your web page
    8·1 answer
  • Which spreadsheet feature could the scholarship committee use to locate applicants who meet the criteria?
    10·1 answer
  • I can’t wait Till Miya’s anniversary skin To be released on september 21st
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!