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
Read a timestamp
easy10 minReport the type of the current timestamp.
- 2
Convert a date to a timestamp
easy10 minReport whether the round trip keeps the value.
- 3
Find the epoch year
easy10 minReport the year of timestamp zero.
- 4
Convert seconds to milliseconds
easy10 minMultiply by a thousand and report the year.
- 5
Sort by timestamp
medium10 minSort the events and report their order.
Find the bug(5)
- 1
Fix the seconds used directly
easy8 minJavaScript expects milliseconds, so seconds land near 1970.
- 2
Fix getTime called on the class
easy8 mingetTime belongs to a date instance, not to Date itself.
- 3
Fix the events sorted by name
easy8 minSorting the names alphabetically ignores when they happened.
- 4
Fix the 1900 offset applied
easy8 mingetFullYear already gives the whole year, with nothing to subtract.
- 5
Fix the elapsed time measured backwards
easy8 minThe 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