Skip to main content

JavaScript Timestamps — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Timestamps 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 a timestamp

    easy10 min

    Report the type of the current timestamp.

  2. 2

    Convert a date to a timestamp

    easy10 min

    Report whether the round trip keeps the value.

  3. 3

    Find the epoch year

    easy10 min

    Report the year of timestamp zero.

  4. 4

    Convert seconds to milliseconds

    easy10 min

    Multiply by a thousand and report the year.

  5. 5

    Sort by timestamp

    medium10 min

    Sort the events and report their order.

Find the bug(5)

  1. 1

    Fix the seconds used directly

    easy8 min

    JavaScript expects milliseconds, so seconds land near 1970.

  2. 2

    Fix getTime called on the class

    easy8 min

    getTime belongs to a date instance, not to Date itself.

  3. 3

    Fix the events sorted by name

    easy8 min

    Sorting the names alphabetically ignores when they happened.

  4. 4

    Fix the 1900 offset applied

    easy8 min

    getFullYear already gives the whole year, with nothing to subtract.

  5. 5

    Fix the elapsed time measured backwards

    easy8 min

    The start must be subtracted from the end.

Ready to write the code?

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

Open the workspace