102k views
1 vote
After the code that follows is executed, what is the value of discountAmount?

var discountAmount;
var orderTotal = 200;
if (orderTotal > 200) {
discountAmount = orderTotal * .3;
} else if (orderTotal > 100) {
discountAmount = orderTotal * .2;
} else {
discountAmount = orderTotal * .1;
}

1 Answer

2 votes

An integer variable is defined and assigned an initial value of
200.

There is an if-else block in the next part of the code. In the first part, a condition is defined in case the value of the defined variable is greater than
200. But since the value of our variable is
200, we will proceed to the next block.

Since the value of our variable is greater than
100, we will follow the commands in the second block.

The expression
.2 means multiplying the current number by
0.2.

Therefore, we will multiply
200 by
0.2.

  • The program output will be therefore as
    40.
User Ruuska
by
5.5k points