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
Who all likes fortnite
Debora [2.8K]

Answer:

my brother

Explanation:

5 0
3 years ago
Read 2 more answers
I. Given the following Java code fragment, what is output? int a, b; String c, d, e; String x = new String("I LOVE"); String y =
Levart [38]

Answer:

Output: The question segment gives the following output--

1) 6

2) 5

3) JAVA!  

4) i love

5) I LOVEjava!

Explanation:

  1. "1) 6" comes because "6" is the length of "I LOVE" which is the value of "x" variable and "x.length( )" statement gives the length of the value of "x" variable which is stored on "a" variable and "a" will be printed with "1)" symbol.
  2. "2) 5" comes because "5" is the length of "java!" which is the value of "y" variable and "y.length( )" statement gives the length of the value of "y" variable which is stored on "b" variable and "b" will be printed with "2)" symbol.
  3. "3) JAVA! " comes because "JAVA!" is the upper case letter of "java!" which is the value of "y" variable and "y.toUpperCase( )" statement change the value from lower case to uppercase of the value of "y" variable which is stored on "c" variable and "c" will be printed with "3)" symbol.
  4. "4) i love " comes because "i love" is the lower case letter of "I LOVE" which is the value of "x" variable and "x.toLowerCase( )" statement change the value from uppercase to lowercase of the value of "x" variable which is stored on "d" variable and "d" will be printed with "4)" symbol.
  5. "5) I LOVEjava! " comes because " I LOVEjava! " is the mixed value of the "x" and "y" variable. It prints because "x.concat(y);" statement combines the x and y value and stored in an "e" variable and "e" will be printed with "5)" symbol.
7 0
3 years ago
What did Francis Ford Coppola and George Lucas create?
garik1379 [7]
. 3d animation markers
7 0
3 years ago
Term of The surroundings and conditions of your workplace
Ainat [17]

Answer:

what

Explanation:

uhh this isnt complete or something i dont know what this is im gonna answer it for the points

8 0
3 years ago
The ________ is the biggest power consumer on a mobile computing device. display CPU memory module hard drive
user100 [1]

Answer:

CPU (Central Processing Unit)

6 0
2 years ago
Other questions:
  • In 1-2 sentences describe how to use the thesaurus in the Word Processor
    11·2 answers
  • A ____ is a type of program that uses a grid to organize and work with data.
    14·1 answer
  • Why is it important to ask an interviewer at least one question at the end of an interview?
    12·2 answers
  • For almost all networks today, including the internet, the communication protocol used is called ____.
    15·1 answer
  • Enterprise Resource Planning (ERP) is an example of a single user database.
    7·1 answer
  • Display the total number of parking tickets.
    5·1 answer
  • IN C++ PLEASE!!!! Define a function FilterStr() that takes a string parameter and returns "Good" if the character at index 4 in
    7·1 answer
  • Anyone know how to fix black screen of death on computer​
    6·1 answer
  • A Product Manager has been given responsibility for overseeing the development of a new software application that will be deploy
    5·1 answer
  • The memory capacity in bits for performing the operation y = f (x) using the table lookup method, where x is an 8-bit number and
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!