Lesson 2 of 4 · 8 minutes
Otherwise: if / else
Often you want one action when a condition is true and a different action when it is false. That is what else is for.
If the condition is true, the if block runs. If it is false,
the else block runs instead.
Exactly one block runs. Never both. Never neither. It is like a fork where both paths lead somewhere.
Exactly one path is always taken.
Loading the editor…
Add console.log("Too young to vote"); inside else. Then test ages 15 and 20.
Quick check
You can now handle both outcomes of a decision.