Skip to main content

JavaScript Debugging — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Debugging 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

    Check the types

    easy10 min

    Report the types of a string and a number.

  2. 2

    Spot the type mismatch

    easy10 min

    Report whether the two values are strictly equal.

  3. 3

    Label what you print

    easy10 min

    Build a labelled report of the width and area.

  4. 4

    Narrow down a pipeline

    easy10 min

    Report the value after each stage of the transformation.

  5. 5

    Find the wrong assumption

    medium10 min

    Convert the value before adding, and report the total.

Find the bug(5)

  1. 1

    Fix the values compared without checking types

    easy8 min

    The two look identical when printed but are different types.

  2. 2

    Fix the unlabelled output

    easy8 min

    Bare values give no clue which is which.

  3. 3

    Fix the silent joining bug

    easy8 min

    The price is text, so plus joins instead of adding.

  4. 4

    Fix the wrong filter boundary

    easy8 min

    The pipeline keeps the wrong values, which printing each stage reveals.

  5. 5

    Fix the type read from the value

    easy8 min

    Printing the value alone does not reveal its type.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace