Skip to main content

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. 1

    Identify a TypeError

    easy10 min

    Report the name when a method is called on null.

  2. 2

    Identify a ReferenceError

    easy10 min

    Report the name when a variable does not exist.

  3. 3

    Identify a SyntaxError

    easy10 min

    Report the name when JSON cannot be parsed.

  4. 4

    Identify a RangeError

    easy10 min

    Report the name when a value is out of range.

  5. 5

    React to the type

    medium10 min

    Report a different message depending on the error type.

Find the bug(5)

  1. 1

    Fix the type compared as text

    easy8 min

    The name is a string but instanceof needs the class.

  2. 2

    Fix the wrong type checked

    easy8 min

    A missing variable is a ReferenceError, not a TypeError.

  3. 3

    Fix the base class checked first

    easy8 min

    Every error is an Error, so that branch catches everything.

  4. 4

    Fix typeof used on an error

    easy8 min

    typeof reports object for every error.

  5. 5

    Fix the name read from the message

    easy8 min

    The 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