A little explanation here. A parking garage charges $5.00 to park for up to three hours. The garage charges an additional $ 1.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24 hour period is $ 18.00. We are assuming that no car parks for longer than 24 hours at a time.
Is there any reason why the total will not calculate when over 3 hours? I have a feeling it has something to do with the sum variable, but I can't put my finger on it.
<script type="text/javascript">
function multiply() {
var hoursParked = document.getElementById('hP').value;
var price = 5.00;
var totalCost = document.getElementById('total');
var totalPayment = (hoursParked * price);
if (hours < 3) {
sum = price * hours;
return sum;
}
else {
sum = ((hours - 3) * 0.5 * price) + (price * hours);
return sum;
}
totalCost.value= sum; }
</script>
</head>
<body><div align="center">
<form id="1">
<input type="text" id="customerName" name="customerName" placeholder="Please enter your name here." size="27px"><br><br>
<input type="number" id="hP" name="hoursParked" placeholder="Hours parked?" min="1" max="24"><br><br>
<input type="button" id="calculateP" name="calculatePayment" value="Calculate" onclick="multiply()"/>
<input type="reset" id="resetBtn" value="Clear"><br><br>
<input type="number" id="total" name="totalCost" placeholder="Your Total Payment" readonly/><hr>
</form>
</div>
</body>
</html>