JavaScript Math Rounding — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Math Rounding 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
Round to the nearest
easy10 minReport four point five rounded.
- 2
Always round down
easy10 minReport four point nine rounded down.
- 3
Always round up
easy10 minReport four point one rounded up.
- 4
Count the pages needed
easy10 minWork out how many pages hold 23 items at ten per page.
- 5
Round to two decimals
medium10 minRound pi to two decimal places as a number.
Find the bug(5)
- 1
Fix floor used for pages
easy8 minRounding down loses the last partial page.
- 2
Fix the negative rounded wrongly
easy8 minfloor goes further down on a negative; trunc just cuts.
- 3
Fix the decimal rounding
easy8 minMultiply before rounding, then divide back.
- 4
Fix ceil used where floor belongs
easy8 minWhole units should round down, not up.
- 5
Fix toFixed used where a number is needed
easy8 mintoFixed returns a string, so the arithmetic joins instead.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace