Answer to Question #278776 in HTML/JavaScript Web Application for Lovely

Question #278776

Hotel Bill


A Hotel is offering discounts to its customers.


Given charge per day dayCharge based on category and number 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

Please provide me corrected output


1
Expert's answer
2021-12-12T12:19:21-0500
'use strict';


process.stdin.resume();
process.stdin.setEncoding('utf-8');


let inputString = '';
let currentLine = 0;


process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});


process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });


    main();    
});


function readLine() {
    return inputString[currentLine++];
}

function main() {
    const dayCharge = JSON.parse(readLine());
    const days = parseInt(readLine());
    let bill, discount;
    bill = dayCharge * days;
    if (days >= 2) {
      discount = 5;
      bill - (bill * discount) / 100;
    }
    if (days >= 5) {
      discount = 15;
      bill - (bill * discount) / 100;
    }
    console.log(`Total bill with the discont is ${bill}`);
}

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