Skip to main content

JavaScript Dates — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Dates 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. 1

    Build a date

    easy10 min

    Create January 15 2026 and report the year.

  2. 2

    Read the month number

    easy10 min

    Report the month number for January.

  3. 3

    Read the day of the month

    easy10 min

    Report the day of the month.

  4. 4

    Parse an ISO string

    easy10 min

    Parse a date string and report the year.

  5. 5

    Copy before changing

    medium10 min

    Change a copy and report the original day.

Find the bug(5)

  1. 1

    Fix the month passed as a real number

    easy8 min

    Months start at zero, so January is 0.

  2. 2

    Fix getDay used for the date

    easy8 min

    getDay gives the weekday, not the day of the month.

  3. 3

    Fix the original changed

    easy8 min

    Setters modify the date in place, so copy first.

  4. 4

    Fix getYear used

    easy8 min

    getYear is an old method; getFullYear is the correct one.

  5. 5

    Fix the date built from a loose string

    easy8 min

    Only the ISO format parses consistently.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace