curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69a890af247de743333bd4d1.md
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:
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");
function getMovieNightCost(day, showtime, numberOfTickets) {
return day;
}
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)}`;
}