JavaScript throw — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript throw 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
Throw on bad input
easy10 minRefuse a negative age and report the message.
- 2
Stop the function
easy10 minShow that nothing after the throw runs.
- 3
Guard a division
easy10 minThrow when dividing by zero and report the message.
- 4
Return rather than throw
easy10 minA missing user is normal, so return null instead.
- 5
Rethrow with context
medium10 minCatch an error and throw a clearer one.
Find the bug(5)
- 1
Fix the string thrown
easy8 minA thrown string has no message property.
- 2
Fix the missing new
easy8 minError must be created with new to be thrown properly.
- 3
Fix the value returned instead of thrown
easy8 minReturning a message lets the caller ignore the problem.
- 4
Fix the throw for a normal outcome
easy8 minA missing user is expected, so it should not throw.
- 5
Fix the missing validation
easy8 minWithout a check the text is coerced and a wrong answer comes back.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace