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.
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} $`);
}
}
Comments
Leave a comment