Skip to main content

JavaScript Numbers — exercises and bug fixes

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

    Add two numbers

    easy10 min

    Report the sum of ten and three.

  2. 2

    Find a remainder

    easy10 min

    Report the remainder when ten is divided by three.

  3. 3

    Test for an even number

    easy10 min

    Report whether four is even.

  4. 4

    Raise to a power

    easy10 min

    Report two to the power of ten.

  5. 5

    Divide by zero

    medium10 min

    Report what dividing by zero gives.

Find the bug(5)

  1. 1

    Fix the number written in quotes

    easy8 min

    A number in quotes is a string, so plus joins it.

  2. 2

    Fix the wrong operator for even

    easy8 min

    Divide gives a fraction; the remainder is what is wanted.

  3. 3

    Fix multiply used for a power

    easy8 min

    Two times ten is not two to the power of ten.

  4. 4

    Fix the division expected to throw

    easy8 min

    Dividing by zero gives Infinity rather than an error.

  5. 5

    Fix the separator treated as a decimal

    easy8 min

    Underscores group digits; a comma does not work in a number.

Ready to write the code?

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

Open the workspace