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
viktelen [127]
4 years ago
9

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);
Computers and Technology
1 answer:
Gekata [30.6K]4 years ago
3 0

Answer:

Add the line numItems=numItems-1 after the 3rd code line.

Explanation:

As the loop is not terminating thus the counter is to be added such that the value is decreased in each iteration. As the last item is entered the value will become 0. Now when the loop will again reach the while point, the condition will become false and thus the loop will be terminated.

You might be interested in
An important factor to consider when purchasing new software is to investigate how much storage the application and associated d
kolbaska11 [484]

Answer: you need data files

Explanation: becusue you need to save

3 0
3 years ago
Please Help ASAP! 30 Points! Will Mark Brainliest! Please Don't Waste Answers! It's Due In 40 Minutes Please Help Me!
weeeeeb [17]

Answer: 2.)  Scratch is a website where you can create your on games from scratch. I chose this because it is very fun to play :D

I hope you pass your test.

Have a great day.

6 0
3 years ago
A telephone-repair technician uses a meter to measure voltage on a phone line. This meter is an example of _____. hardware softw
andrew-mc [135]
A meter to measure voltage would be an example of hardware.
5 0
3 years ago
Read 2 more answers
Why does a computer need programs? ​
Yuri [45]
To run successfully. That was the answer on my quiz. Sorry if it doesn’t help
3 0
3 years ago
Read 2 more answers
Which of the following actions would help people determine their interests?
lorasvet [3.4K]
That depends on what the actions are, and what their personality is like.
8 0
3 years ago
Other questions:
  • An empty frame used to reserve space for a picture to be inserted at a later time is know as what
    6·1 answer
  • What type of data is not defined and does not follow a specified format and is typically free-form text such as emails, Twitter
    13·1 answer
  • 1st row has 3 possible answers software program, web page, and web browser
    8·1 answer
  • Academic databases are the best place to look for
    12·1 answer
  • In this problem, you will fill in the code for a function count_digits(val) that takes a positive integer, val, and returns a li
    12·1 answer
  • SLA:
    14·1 answer
  • Consider the following method.
    14·1 answer
  • Difference between the four generations of computers in a tabular form​
    8·1 answer
  • Write a program that uses the Purchase class in 5.13. Set the prices to the following: Oranges: 10 for $2.99 Eggs: 12 for $1.69
    11·1 answer
  • Write a sub-program to display the acceleration of car. The program should ask initial velocity, final velocity, and time taken
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!