Answer to Question #168834 in HTML/JavaScript Web Application for Aryan Thakur

Question #168834

A parking garage charges a $2.00 minimum fee to park for up to three hours. The 

garage charges an additional $0.50 per hour for each hour or part thereof in excess of 

three hours. The maximum charge for any given 24-hour period is $10.00. Assume that 

no car parks for longer than 24 hours at a time. Write a script that calculates and 

displays the parking charges for each customer who parked a car in this garage 

yesterday. You should input from the user the hours parked for each customer. The 

program should display the charge for the current customer and should calculate and 

display the running total of yesterday's receipts. The program should use the function 

calculate-Charges to determine the charge for each customer. Use a prompt dialog to 

obtain the input from the user.


1
Expert's answer
2021-03-04T10:46:31-0500
calculateCharges();

function calculateCharges() {
    let cost = 0;
    let sum = 0;

    while(true) {
        let hours = prompt('Enter hours');

        if (!hours) {
            alert(`summary =  ${sum} $`);
            return false
        }

        if (hours >= 24) {
            sum += 10;
            cost = 10;
        } else if(hours <= 3) {
            sum += 2;
            cost = 2;
        } else {
            sum += 2 + 0.5 * Math.ceil(hours);
            cost = 2 + 0.5 * Math.ceil(hours)
        }

        alert(`charge =  ${cost} $`);
        alert(`summary =  ${sum} $`);
    }
}

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
APPROVED BY CLIENTS