JavaScript Ternary Operator — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Ternary Operator lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Choose between two values
easy10 minReport adult when the age is 18 or more.
- 2
Pick the singular or plural
easy10 minReport the right wording for a count of one.
- 3
Return from a function
easy10 minReturn a lower fee for members.
- 4
Chain two ternaries
easy10 minReport a grade of B for a score of 75.
- 5
Use it inside a string
medium10 minBuild a sentence that changes with the value.
Find the bug(5)
- 1
Fix the branches the wrong way round
easy8 minThe true and false values have been swapped.
- 2
Fix the singular and plural swapped
easy8 minA count of two should read items, not item.
- 3
Fix the missing brackets
easy8 minWithout brackets the join happens before the choice.
- 4
Fix the comparison that is always true
easy8 minA single equals assigns instead of comparing.
- 5
Fix the grade boundaries
easy8 minA score of 75 should be a B, not a C.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace