Reading an error
JavaScript · Unit 9: Errors and exceptions
- Full plan
- JavaScript
- 10 exercises
When something goes wrong, JavaScript stops and tells you three things: the error type, a message and the line.
In ReferenceError: totl is not defined (line 3), the type is ReferenceError, the message says totl doesn't exist, and the line tells you where to look.
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Multiple choice
You get this error:
TypeError: name.toUpper is not a function. Which part is the error type?2. Multiple choice
You get
ReferenceError: pirce is not definedon line 2. What happened?3. Find the bug
Running this gives
ReferenceError: totl is not defined. It should print the total, 90. Which line has the error?4. Find the bug
This program should print "Hello" and then "Emma". Which line has the error?
5. Multiple choice
If you delete the closing quote on line 3, leaving
console.log("three);, what happens when you run it?6. Find the bug
This program should print the grocery list, one item per line. Which line has the error?
7. Multiple choice
Now the change is different: on line 3 you write
console.log(three);, without quotes. What happens when you run it?8. Put the lines in order
Order the lines to print the bill with a 10% tip, without getting a
ReferenceError.9. Complete the code
This code gave
ReferenceError: ages is not definedon line 2. Complete line 1 to fix it.10. Find the bug
You get
ReferenceError: total is not definedon line 3. The variable should be calledtotal. Which line has the error?
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.