The browser storage localStorage is not available. Either your browser does not support it or you have disabled it or the maximum memory size is exceeded. Without localStorage your solutions will not be stored.
else if
If you want to distinguish multiple cases, you can supplement an
if
with any number of
else if
. Finally, a single else
can be added.
let message;
if (amount > 1000) {
message = 'Too high. No payout possible!';
} else if (amount < 10) {
message = 'Too low. No payout possible!';
} else {
message = 'The amount will be paid out!';
}
First it is checked whether amount
is greater than 1000
.
If so, the 'Too high ...' message is set and the code will be continued at the end of the entire block.
If not, it is checked whether amount
is less than 10
.
If so, the 'Too low ...' message is set and the code will be continued at the end of the entire block.
If no condition is met, the final else
block is executed.Exercise
Write a function
Example:
addWithSurcharge
that adds two amounts with surcharge.
For each amount less than or equal to 10
, the surcharge is 1
.
For each amount greater than 10
and less than or equal to 20
, the surcharge is 2
.
For each amount greater than 20
, the surcharge is 3
.Example:
addWithSurcharge(10, 30)
should return 44
.