Skip to main content

JavaScript Date Components — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Date Components 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

    Read the hours

    easy10 min

    Report the UTC hours of the date.

  2. 2

    Read the weekday number

    easy10 min

    Report the weekday number, where Sunday is zero.

  3. 3

    Name the weekday

    easy10 min

    Use an array to turn the number into a name.

  4. 4

    Change the year

    easy10 min

    Set the year to 2027 and report it.

  5. 5

    Build a padded time

    medium10 min

    Show the time with leading zeros.

Find the bug(5)

  1. 1

    Fix getDate used for the weekday

    easy8 min

    getDate is the day of the month; getDay is the weekday.

  2. 2

    Fix the unpadded time

    easy8 min

    Single digits need a leading zero.

  3. 3

    Fix the year set with the wrong method

    easy8 min

    setUTCMonth changes the month, not the year.

  4. 4

    Fix the setter never called

    easy8 min

    The day was read without ever being changed.

  5. 5

    Fix the minutes read as seconds

    easy8 min

    The wrong getter gives the wrong part.

Ready to write the code?

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

Open the workspace