Skip to main content

JavaScript Number Formatting — exercises and bug fixes

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

    Group the digits

    easy10 min

    Format a large number for British readers.

  2. 2

    Format as currency

    easy10 min

    Show the price in pounds.

  3. 3

    Format a percentage

    easy10 min

    Show a quarter as a percentage with no decimals.

  4. 4

    Keep trailing zeros

    easy10 min

    Show a whole number with two decimal places.

  5. 5

    Reuse a formatter

    medium10 min

    Build one Intl formatter and use it twice.

Find the bug(5)

  1. 1

    Fix the percentage passed as a whole number

    easy8 min

    Percent style multiplies by one hundred.

  2. 2

    Fix the missing currency code

    easy8 min

    Currency style needs the currency named.

  3. 3

    Fix toFixed used for grouping

    easy8 min

    toFixed sets decimals but never groups the digits.

  4. 4

    Fix the trailing zeros dropped

    easy8 min

    A whole number needs a minimum number of decimals.

  5. 5

    Fix the currency built by hand

    easy8 min

    Joining a symbol misses the digit grouping.

Ready to write the code?

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

Open the workspace