JavaScript Date Pitfalls — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Date Pitfalls 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 a rollover
easy10 minBuild January 32 and report the month number it lands on.
- 2
Detect an invalid date
easy10 minReport that an unparseable string gives an invalid date.
- 3
Write a validity check
easy10 minWrite a helper and use it on a good date.
- 4
Protect the caller's date
easy10 minAdd a week to a copy and report the original day.
- 5
See February roll over
medium10 minBuild February 30 and report the month it lands on.
Find the bug(5)
- 1
Fix the invalid date left unchecked
easy8 minAn invalid date gives NaN rather than throwing.
- 2
Fix the validity check using equality
easy8 minAn invalid date is never equal to NaN.
- 3
Fix the rollover assumed to throw
easy8 minAn out-of-range day rolls over silently.
- 4
Fix the helper changing its argument
easy8 minThe caller's date must not be modified.
- 5
Fix the month passed as a human number
easy8 minPassing 12 for December rolls into the next year.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace