---
id: 69a890af247de743333bd4d1
title: "Challenge 228: Movie Night"
challengeType: 28
dashedName: 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"`.

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

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

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

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

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

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

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

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

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

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

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

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

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

# --seed--

## --seed-contents--

```js
function getMovieNightCost(day, showtime, numberOfTickets) {

  return day;
}
```

# --solutions--

```js
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)}`;
}
```
