JavaScript Number Precision — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Number Precision 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
See the precision error
easy10 minReport whether adding a tenth to two tenths gives exactly three tenths.
- 2
Compare with a tolerance
easy10 minCheck the difference is small enough instead.
- 3
Round for display
easy10 minShow the total rounded to two decimal places.
- 4
Work in whole numbers
easy10 minAdd the values as pence and convert back to pounds.
- 5
Show whole numbers are exact
medium10 minReport whether one plus two is exactly three.
Find the bug(5)
- 1
Fix the exact decimal comparison
easy8 minDecimals should be compared with a tolerance.
- 2
Fix the accumulated drift
easy8 minAdding a tenth ten times does not give exactly one.
- 3
Fix the money stored as pounds
easy8 minStoring pence keeps the arithmetic exact.
- 4
Fix the tolerance that is too tight
easy8 minA tolerance of zero is the same as an exact comparison.
- 5
Fix the missing absolute value
easy8 minWithout abs, a negative difference slips under any tolerance.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace