Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.0 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68f6587287ad1f4ad39b0c82 Challenge 96: Is It the Weekend? 28 challenge-96

--description--

Given a date in the format "YYYY-MM-DD", return the number of days left until the weekend.

  • The weekend starts on Saturday.
  • If the given date is Saturday or Sunday, return "It's the weekend!".
  • Otherwise, return "X days until the weekend.", where X is the number of days until Saturday.
  • If X is 1, use "day" (singular) instead of "days" (plural).
  • Make sure the calculation ignores your local timezone.

--hints--

daysUntilWeekend("2025-11-14") should return "1 day until the weekend.".

assert.equal(daysUntilWeekend("2025-11-14"), "1 day until the weekend.");

daysUntilWeekend("2025-01-01") should return "3 days until the weekend.".

assert.equal(daysUntilWeekend("2025-01-01"), "3 days until the weekend.");

daysUntilWeekend("2025-12-06") should return "It's the weekend!".

assert.equal(daysUntilWeekend("2025-12-06"), "It's the weekend!");

daysUntilWeekend("2026-01-27") should return "4 days until the weekend.".

assert.equal(daysUntilWeekend("2026-01-27"), "4 days until the weekend.");

daysUntilWeekend("2026-09-07") should return "5 days until the weekend.".

assert.equal(daysUntilWeekend("2026-09-07"), "5 days until the weekend.");

daysUntilWeekend("2026-11-29") should return "It's the weekend!".

assert.equal(daysUntilWeekend("2026-11-29"), "It's the weekend!");

--seed--

--seed-contents--

function daysUntilWeekend(dateString) {

  return dateString;
}

--solutions--

function daysUntilWeekend(dateString) {
  const [year, month, day] = dateString.split("-").map(Number);
  const date = new Date(Date.UTC(year, month - 1, day));

  const dayOfWeek = date.getUTCDay();

  if (dayOfWeek === 6 || dayOfWeek === 0) {
    return "It's the weekend!";
  }

  const daysUntilSaturday = (6 - dayOfWeek);
  return `${daysUntilSaturday} day${daysUntilSaturday === 1 ? "" : "s"} until the weekend.`;
}