8.0k views
0 votes
Write a switch statement to select an operation based on the value of inventory. Increment total_paper by paper_order if inventory is 'B' or 'C'; increment total_ribbon by ribbon_order if inventory is 'D', 'F', or 'E'; increment total_label by label_order if inventory is 'A' or 'X'. Do nothing if inventory is 'M'. Display error message if value of inventory is not one of these 6 letters.

1 Answer

6 votes

Answer:

switch(inventory) X:

total_label += label_order;

break;

case M:

break;

default:

console.log("Error! Invalid inventory value");

Step-by-step explanation:

The switch keyword is a control statement used in place of the if-statement. It uses the 'case' and 'break' keywords to compare input values and escape from the program flow respectively. The default keyword is used to accommodate input values that do not match the compared values of the cases.

User Rleir
by
2.9k points