This is the full question
Write a complete for charging the parking fee for each customer based on the number of hour parking. Ask user to enter the total hour using prompt()
Calculate the amount of charge that a customer has to pay using the function calcCharge().
This function receive the total hour or parking through its parameter. It then calculate and returns the amount of charges to the customer.
The formula to calculate the amount of charges to the customer : In the first hour, the charge is RM 1.00. In the next hour, the addition charge is RM 0.50 per hour. The maximum charge is RM 10.00. Calculate the total charge of all the customers using function calcTotal(). Display the amount of charges for a customer. Display total charge of all customer using alert()
and ive tried to do the code but fail.
i fail to display the total charge of a customer and total charge for all customers.
i hope somebody willing to help me, thanks!
<html>
<head><title>Calculate Parking Hours</title>
<script type="text/javascript">
function calcCharge()
{
var hour=parseInt(document.fee.hour.value);
var tot;
if (hour==1)
tot=1;
else if (hour>1 && hour<=20)
tot=1+0.5*(hour-1);
else
tot=10;
document.write("The total charge is : RM "+tot);
}
function calcTotal()
{
var totCha;
totCha=parseInt(totCha);
totCha+=document.tot.value;
alert("Total charge all customers"+totCha);
}
</script>
</head>
<body onload="calcTotal()">
<form name="fee" method="post">
Hour : <input name="hour" type="text"><br>
<input type="submit" name="submit" value="Total Charge" onclick="calcCharge()">
</form>
</body>
</html>