Catch the error and report a message.
Acceptance criteria
- 1.#out should show something went wrong.
JavaScript Tutorial · JavaScript Errors
These 10 tasks go with the JavaScript Errors chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “An error stops the current code and travels up until something handles it.” .
1.Catch a failureexercise · easy · 10 min
Catch the error and report a message.
Passes when: #out should show something went wrong.
2.Carry on afterwardsexercise · easy · 10 min · practice plan
Show that the program continues after a caught error.
Passes when: #out should show one caught carried on.
3.Read the error nameexercise · easy · 10 min · practice plan
Report the name of the error that was thrown.
Passes when: #out should show TypeError.
4.Read the error messageexercise · easy · 10 min · practice plan
Report the message of an error you throw yourself.
Passes when: #out should show it broke.
5.Let an error travel upexercise · medium · 10 min · practice plan
Catch at the top an error thrown two functions down.
Passes when: #out should show caught at the top.
6.Fix the missing try blockbug fix · easy · 8 min
Without a try the error stops everything after it.
Passes when: #out should show one caught carried on.
7.Fix the message read as a namebug fix · easy · 8 min · practice plan
The name is the type; the message is the description.
Passes when: #out should show it broke.
8.Fix the logic error treated as catchablebug fix · easy · 8 min · practice plan
Wrong brackets do not throw, so try cannot help.
Passes when: #out should show 15.
9.Fix the catch placed too deepbug fix · easy · 8 min · practice plan
The inner function swallows an error the caller needed to see.
Passes when: #out should show caught at the top.
10.Fix the code placed after the failurebug fix · easy · 8 min · practice plan
Statements after the throwing line inside try never run.
Passes when: #out should show moved outside.
Between them these tasks cover Runtime errors, Error object and Propagation.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.