oldskool
Oldie but a goodie
- Messages
- 1,760
- Location
- Maine, USA
As I have stated before with other problems, I am a student, and not looking for the work to be done, but just a hint at what I am doing wrong. Thanks for any help anyone can give !
I am writing a Javascript program to calculate gross pay, and it is supposed to figure in overtime pay as well. Anything 41 hours and up is time and one-half pay.
I have this all working except for one thing, I can't seem to figure out why the overtime feature isn't working. First I will display my code based on straight 40 hours, then I will post the IF statement that I think would work, but I am apparently either not typing it out syntactically correct, or logically correct or both.
And here is the code I am hoping I can insert if it is correct, but I don't know if it is logic or syntax error, or both as I said....
I am writing a Javascript program to calculate gross pay, and it is supposed to figure in overtime pay as well. Anything 41 hours and up is time and one-half pay.
I have this all working except for one thing, I can't seem to figure out why the overtime feature isn't working. First I will display my code based on straight 40 hours, then I will post the IF statement that I think would work, but I am apparently either not typing it out syntactically correct, or logically correct or both.
Code:
<html>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Wages HTML</title>
<meta http-equiv="content-type" content="text/html;
charset=iso-8859-1" />
<br />
<br />
<br />
<br />
<center><p><form name="gross"><h3><b>Please enter your base hourly pay, and click the button below</b><h3>
<h5><i>Enter the # of hours worked this week</i><h5><p>
<script type="text/javascript">
/* <![CDATA[ */
//code written by Eric Maddan
function grossPay(pay)
{
var grossWage=parseFloat(pay);
var hrsWorked=parseFloat(document.gross.hours.value);
var gross=(grossWage * hrsWorked);
var outBoxtext = (" $ " + " " + " " + gross) ;
document.gross.pay.value=outBoxtext;
}
</script>
<center>
<input type="text" name="inputText" size="20"><p>
Your hourly wage in dollars and cents is:
<br />
<br />
<input type="text" name="hours" size="20">
<br />
<br />
<br />
<br />
Your pay for this week is :
<br />
<br />
<input name="pay" size="20"><br /><br />
<input type="button" value="Calculate Gross Pay"
OnClick="grossPay(inputText.value);"></center>
</form>
</center>
</script>
</head>
<body>
<script type="text/javascript">
/* <![CDATA[ */
/* ]]> */
</script>
</script>
</body>
</html>
And here is the code I am hoping I can insert if it is correct, but I don't know if it is logic or syntax error, or both as I said....
Code:
if (hrsWorked >= 41)
{
hrsWorked = ((hrsWorked + (hrsWorked / 2));
document.gross.hours.value=hrsWorked;
}
else
{
hrsWorked = hrsWorked;
}