Sometimes using 3-5 lines of code to write an if/else block is overkill. The ternary operator makes it easy to write a conditional as a single expression.
const price = isMember ? "$2.00" : "$10.00";
I like to read it in English as:
If
isMemberis true, evaluate to$2.00, otherwise evaluate to$10.00.
The same logic using if/else would be:
let price;
if (isMember) {
price = "$2.00";
} else {
price = "$10.00";
}
Ternary's latin root means "3", and it's the only JavaScript operator that takes three operands.
:)On line 6, create a variable called messageStatus and use a ternary operator to set the value of that variable to either:
"Processing": the number of retries is less than the limit"Failed": the number of retries is greater than or equal to the limitUse the ternary operator and a comparison operator to dynamically determine which string to set as the value of messageStatus to.