Hotel Bill
A Hotel is offering discounts to its customers.
Given charge per day
dayCharge based on category and numbers of days customer stayed days as inputs, write a JS arrow function to return the total bill with the discount.
Quick Tip
Apply discounts on the following basis,
Sample Input 1
200
3
Sample Output 1
570
getting 600 but actual output is 570.
Sample Input 2
180
1
Sample Output 2
180
const hotelBill = (dayCharge, days) => {
let discount = 0;
if (days > 2 && days <= 15) {
discount = 5;
} else if (days > 15) {
discount = 15;
}
return dayCharge * days - (dayCharge * days * discount) / 100
}
console.log(hotelBill(200, 3));
console.log(hotelBill(180, 1));
Comments
Leave a comment