Home › Learn › JavaScript › Getting started

Reading error messages

Lesson 5 of 40. Learn what ReferenceError, TypeError, and SyntaxError mean by fixing them.

When code cannot run, JavaScript throws an error with a name and a message. ReferenceError: totl is not defined means you used a name that was never declared, usually a typo. TypeError: x is not a function or Cannot read properties of undefined means a value is not what you assumed. SyntaxError: Unexpected token means the code could not even be parsed: a missing quote, bracket, or parenthesis, usually a line or two before where it is reported.

Fix the first error, run again, and the next one appears. That is the normal rhythm.

Your task

The starter has three bugs. Fix them so the program prints Total: 42 and then Done, without changing what it is trying to do.

Hint 1

Run it and read the error. A SyntaxError stops everything, so fix that first.

Hint 2

Then the misspelled variable name.

Show the solution
const price = 40;
const tip = 2;
const total = price + tip;
console.log("Total: " + total);
console.log("Done");

    Runs in an isolated web worker in this tab; nothing is sent anywhere.