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.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69a890af247de743333bd4d1 Challenge 228: Movie Night 28 challenge-228

--description--

Given a string for the day of the week, another string for a showtime, and an integer number of tickets, return the total cost of the movie tickets for that showing.

The given day will be one of:

  • "Monday"
  • "Tuesday"
  • "Wednesday"
  • "Thursday"
  • "Friday"
  • "Saturday"
  • "Sunday"

The showtime will be given in the format "H:MMam" or "H:MMpm". For example "10:00am" or "10:00pm".

Return the total cost in the format "$D.CC" using these rules:

  • Weekend (Friday - Sunday): $12.00 per ticket.
  • Weekday (Monday - Thursday): $10.00 per ticket.
  • Matinee (before 5:00pm): subtract $2.00 per ticket (except on Tuesdays).
  • Tuesdays: all tickets are $5.00 each.

--hints--

getMovieNightCost("Saturday", "10:00pm", 1) should return "$12.00".

assert.equal(getMovieNightCost("Saturday", "10:00pm", 1), "$12.00");

getMovieNightCost("Sunday", "10:00am", 1) should return "$10.00".

assert.equal(getMovieNightCost("Sunday", "10:00am", 1), "$10.00");

getMovieNightCost("Tuesday", "7:20pm", 2) should return "$10.00".

assert.equal(getMovieNightCost("Tuesday", "7:20pm", 2), "$10.00");

getMovieNightCost("Wednesday", "5:40pm", 3) should return "$30.00".

assert.equal(getMovieNightCost("Wednesday", "5:40pm", 3), "$30.00");

getMovieNightCost("Monday", "11:50am", 4) should return "$32.00".

assert.equal(getMovieNightCost("Monday", "11:50am", 4), "$32.00");

getMovieNightCost("Friday", "4:30pm", 5) should return "$50.00".

assert.equal(getMovieNightCost("Friday", "4:30pm", 5), "$50.00");

getMovieNightCost("Tuesday", "11:30am", 1) should return "$5.00".

assert.equal(getMovieNightCost("Tuesday", "11:30am", 1), "$5.00");

--seed--

--seed-contents--

function getMovieNightCost(day, showtime, numberOfTickets) {

  return day;
}

--solutions--

function getMovieNightCost(day, showtime, numberOfTickets) {
  let price;

  if (day === "Tuesday") {
    price = 5;
  } else {
    if (["Friday", "Saturday", "Sunday"].includes(day)) {
      price = 12;
    } else {
      price = 10;
    }

    const hour = parseInt(showtime.split(":")[0]);
    const period = showtime.slice(-2);

    let hour24 = hour;

    if (period === "pm" && hour !== 12) hour24 += 12;
    if (period === "am" && hour === 12) hour24 = 0;

    if (hour24 < 17) {
      price -= 2;
    }
  }

  const total = price * numberOfTickets;

  return `$${total.toFixed(2)}`;
}