/    Sign up×
Community /Pin to ProfileBookmark

Help me please Im a noob

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” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<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

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@StashXJan 13.2005 — I made this for you....

Hope to help!!!?

I've made some changes...


Keep going through JavaScript... ?


[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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
var totalres=0;
function calculateCharges (form){
var _money=Math.ceil(form.fhours.value);
if (_money >= 0) {
if (_money == false) {
ownholder.innerText="No Dice.";
}
else {
if (_money <= 3) {
price=2.00;
}
else if (_money > 3 && _money <= 18){
price=Number(0.5 * (_money - 3) + 2);
}
else {
price=10.00;
}
ownholder.innerText="You owe: $" + price + ".";
totalres=totalres + price;
totalholder.innerText="Total receipts: $" + totalres;
}
}
else ownholder.innerText="Error with the input.";
form.fhours.value="";
form.fhours.focus();
}
</script>
</head>

<body>
<form name="myForm">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table border="0" width="100%">
<tr>
<td>Enter Number of Hours Parked<br>
<input type="text" name="fhours"><br>
<input type="button" value="Submit" onClick="calculateCharges(this.form);"><br>
</td>
</tr>
<tr>
<td height="30" valign="middle" align="center"><div id="ownholder"></div>
</td>
</tr>
<tr>
<td><div id="totalholder">Total receipts: $0.00</div></td>
</tr>
</table>
</form>
</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@Bad_OscarauthorJan 13.2005 — Did this work for you? When I enter a value and hit submit, nothing happens.


thanks for your help!
Copy linkTweet thisAlerts:
@StashXJan 13.2005 — yes.?

I write anything chars or numbers and when CLICKING Submit it works....

If you press Enter I know it wont do anything...

YOU HAVE TO CLICK THE SUBMIT BUTTON...
Copy linkTweet thisAlerts:
@Bad_OscarauthorJan 13.2005 — I know you have to hit submit but for some reason nothing happens.

thanks for all your help
Copy linkTweet thisAlerts:
@Bad_OscarauthorJan 13.2005 — Sorry about that, it works fine. I was trying it in Netscape which does not support the <DIV NAME> tag and that's why nothing happened. Thanks alot I really appreciate the help!

Cheers.
Copy linkTweet thisAlerts:
@StashXJan 15.2005 — It will work in Netscape if you just change the div to Text box....

Glad for help u out....?
×

Success!

Help @Bad_Oscar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...