JavaScript Error Types — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Error Types 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
Identify a TypeError
easy10 minReport the name when a method is called on null.
- 2
Identify a ReferenceError
easy10 minReport the name when a variable does not exist.
- 3
Identify a SyntaxError
easy10 minReport the name when JSON cannot be parsed.
- 4
Identify a RangeError
easy10 minReport the name when a value is out of range.
- 5
React to the type
medium10 minReport a different message depending on the error type.
Find the bug(5)
- 1
Fix the type compared as text
easy8 minThe name is a string but instanceof needs the class.
- 2
Fix the wrong type checked
easy8 minA missing variable is a ReferenceError, not a TypeError.
- 3
Fix the base class checked first
easy8 minEvery error is an Error, so that branch catches everything.
- 4
Fix typeof used on an error
easy8 mintypeof reports object for every error.
- 5
Fix the name read from the message
easy8 minThe message describes the problem; the name gives the type.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace