I’m taking a javascript course and am working on one of the first projects. I can’t figure out how to make it work and am in huge need of some assistance. I can’t figure out what to loop and where to do it and how to stor the variables as the program continues. I would be extremely grateful if someone could point me in the right direction. I will first post the question and then follow with what I got so far. Keep in mind I’m an entire NOOB. Don’t laugh at me please.
QUESTION:
A parking garage charges a $2.00 minimum fee to park for up to three hours. It 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 calculateCharges to determine the charge for each customer. Use HTML form to obtain the input from the user.
WHAT I GOT:
[COLOR=Indigo]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “
<html xmlns=”
<head>
<title>Javascript</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<style type=”text/css”>
<!–
body {
font-family: Arial, Helvetica, sans-serif;
color: #666666;
text-align: center;
}
–>
</style>
<script language=”javascript”>
<!–Hiding Javascript
function calculateCharges (form){
var _money=Math.ceil(form.fhours.value);
if (_money <= 3 && _money > 0) {
document.write (“You owe: $2.00”);
}
else if (_money > 3 && _money <= 18){
document.write(“You owe: $” + Number(0.5 * (_money – 3) + 2) + “.”);
}
else if (_money == false){
document.write(“No Dice”);
}
else {
document.write(“You owe $10.00”);
}
}
</script>
</head>
<body>
<br>
<br>
<script language=”javascript”>
</script>
<form name=”myForm” action=”” method=”get”>Enter Number of Hours Parked<br>
<input type=”text” name=”fhours”><br>
<input type=”button”
value=”Submit” onClick=”calculateCharges(this.form);”>
<input type=”button” value=”End List” onClick=””><br>
</form>
<br>
<br>
</body>
</html>[/COLOR]
I would greatly appreciate some assistance.
TIA