JavaScript Type Coercion — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Type Coercion 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
See plus join
easy10 minReport what a string plus a number gives.
- 2
See minus convert
easy10 minReport what a string minus a number gives.
- 3
Watch the order matter
easy10 minReport the result of 1 plus 2 plus the text 3.
- 4
Convert a boolean
easy10 minReport what true plus one gives.
- 5
Avoid the surprise
medium10 minConvert before adding so the answer is arithmetic.
Find the bug(5)
- 1
Fix the accidental join
easy8 minThe values are being joined instead of added.
- 2
Fix the order of operations
easy8 minThe numbers should be added before the text is joined.
- 3
Fix the total built as text
easy8 minStarting with an empty string joins every number.
- 4
Fix the boolean used as text
easy8 minThe boolean should be counted as a number.
- 5
Fix the comparison of mixed types
easy8 minConvert the text before comparing it as a number.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace