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
Group the digits
easy10 minFormat a large number for British readers.
- 2
Format as currency
easy10 minShow the price in pounds.
- 3
Format a percentage
easy10 minShow a quarter as a percentage with no decimals.
- 4
Keep trailing zeros
easy10 minShow a whole number with two decimal places.
- 5
Reuse a formatter
medium10 minBuild one Intl formatter and use it twice.
Find the bug(5)
- 1
Fix the percentage passed as a whole number
easy8 minPercent style multiplies by one hundred.
- 2
Fix the missing currency code
easy8 minCurrency style needs the currency named.
- 3
Fix toFixed used for grouping
easy8 mintoFixed sets decimals but never groups the digits.
- 4
Fix the trailing zeros dropped
easy8 minA whole number needs a minimum number of decimals.
- 5
Fix the currency built by hand
easy8 minJoining 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