Command Palette

Search for a command to run...

Hectal
Phase 4: Strings, Numbers and Dates
JavaScript · Exercise 5 of 5 Previous
Beginner

An event countdown card

Build a card for the Hectal JS Meetup, which starts at 2024-02-10T12:30:00Z. To keep the result testable, "now" is fixed at 2024-01-15T10:30:00Z.

1. daysUntil(now, target) takes two Dates and returns how many calendar days (in UTC) are between their dates, ignoring the time of day: from 15 Jan 10:30 to 16 Jan 01:00 is 1 day.

2. countdownText(days) returns Today! for 0, 1 day to go for 1, 26 days to go for 26 (any number above 1), and Event over for negative numbers.

3. Show the event's date and time in #when, formatted for India (en-IN) in the Asia/Kolkata time zone, with the weekday, day, month name and year and the time. Put countdownText(...) in #countdown.

What Check tests

  1. daysUntil gives 26 from 15 Jan to 10 Feb 2024
  2. daysUntil counts calendar days, not 24-hour blocks
  3. countdownText handles today, one day, many days and the past
  4. The card shows 26 days to go
  5. The date is shown in India time with the weekday and month name

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.