Sobes.tech
Junior — Senior

Hotel accommodation cost calculation

livecode

Task condition

Determining the price per night at a hotel. The function takes two parameters:

  1. Number of nights (mandatory).
  2. Check-in date (optional). If the date is not specified, the current day is used. Cost of stay on weekdays (Monday to Friday) — 1200 rubles. Cost of stay on weekends (Saturday, Sunday) — 2000 rubles.
const rates = {
    weekday: 1200,
    holidays: 2000,
};

function calculateBooking(nights, startDate) {
    let total = 0;
    return total;
}

console.log(calculateBooking(7)); // 31000
console.log(calculateBooking(3, new Date("2023-11-10"))); // 5000