Loading...
beginner
Problem 03 • Step 03
If/Then/Else
This is the main event. The if expression lets the evaluator choose between two paths based on a condition.
["if", condition, consequent, alternative]
The evaluator should:
- Evaluate the condition — it produces
trueorfalse - If
true, evaluate the consequent and return its result - If
false, evaluate the alternative and return its result
For example:
evaluate(["if", [5, ">", 3], 10, 20]) // -> 10
evaluate(["if", [1, "==", 2], 42, 99]) // -> 99
TIP
Only evaluate the branch you need. The other branch should not be evaluated at all.
Fill in the "if" rule. You receive three arguments: condition, consequent, and alternative.