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.
Build January 32 and report the month number it lands on.
Report that an unparseable string gives an invalid date.
Write a helper and use it on a good date.
Add a week to a copy and report the original day.
Build February 30 and report the month it lands on.
An invalid date gives NaN rather than throwing.
An invalid date is never equal to NaN.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspaceAn out-of-range day rolls over silently.
The caller's date must not be modified.
Passing 12 for December rolls into the next year.