Answer to Question #207166 in HTML/JavaScript Web Application for jayanth

Question #207166

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

  • The formula for bill is,
  • bill = dayCharge * days
  • The formula to calculate the discounted bill,
  • bill - (bill * discount) / 100

Apply discounts on the following basis,

  • 5%, if the customer stays more than 2 days
  • 15%, if the customer stays more than 5 days

Input

  • The first line of input contains a number dayCharge
  • The second line of input contains a number days

Output

  • The output should be a single line containing the total bill with the discount

Sample Input 1

200

3

Sample Output 1

570

Sample Input 2

180

1

Sample Output 2

180




1
Expert's answer
2021-06-15T14:19:12-0400
function 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));

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS