Skip to main content

JavaScript Math Object — exercises and bug fixes

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

    Remove the sign

    easy10 min

    Report the absolute value of minus five.

  2. 2

    Find a square root

    easy10 min

    Report the square root of 144.

  3. 3

    Raise to a power

    easy10 min

    Use Math.pow to report two to the tenth.

  4. 4

    Measure a distance

    easy10 min

    Report how far apart three and eight are.

  5. 5

    Work out a circle area

    medium10 min

    Report the rounded area of a circle of radius three.

Find the bug(5)

  1. 1

    Fix Math used with new

    easy8 min

    Math is not a constructor.

  2. 2

    Fix the missing Math prefix

    easy8 min

    sqrt is a method of Math, not a global function.

  3. 3

    Fix the distance without abs

    easy8 min

    The difference is negative, so the sign must be removed.

  4. 4

    Fix PI written by hand

    easy8 min

    Use the built-in constant rather than a rough value.

  5. 5

    Fix the arguments to pow swapped

    easy8 min

    The base comes first and the exponent second.

Ready to write the code?

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

Open the workspace