|
-
Feb 4th, 2013, 12:39 PM
#1
Thread Starter
New Member
Seeking assistance with my JS...please!
I'm trying to get it to prompt for hours worked, then rate per hour...which works fine. Then I cannot get it to display the adjusted pay when taxes are deducted. Any assistance is appreciated.
--------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SimpleCustomer</title>
<script type="text/javascript">
function calcPay(hours, rate){
var regTime = 40;
var overTime = 1.5;
var calcPay;
if (hours > 40)
calcPay = hours * rate + ((hours - regTime) * (overTime * rate));
else
calcPay = hours * rate;
return calcPay.toFixed()
}
function adjCalcPay(calcPay){
var fedTaxes = 0.31;
var stateTaxes = 0.08;
var localTaxes = 0.02;
var takeHome = calcPay - ((calcPay * fedTaxes) + (calcPay * stateTaxes) + (calcPay * localTaxes));
return takeHome.toFixed()
}
</script>
</head>
<body>
<h1>SimpleCustomer test</h1>
<script type="text/javascript">
var hours = prompt("Enter hours worked");
var rate = prompt("Enter hourly rate");
var calcPay;
var takeHome;
calcPay = calcPay(hours, rate);
takeHome = adjCalcPay(fedTaxes, stateTaxes, localTaxes);
document.writeln("Take home pay after working " + hours + " hours with pay rate of $" + rate + " per hour, will be $" + calcPay + ".");
document.writeln("Take home pay after working " + hours + " hours with pay rate of $" + rate + " per hour, will be $" + takeHome + " after taxes.");
</script>
</body>
</html>
-
Feb 9th, 2013, 09:50 AM
#2
Re: Seeking assistance with my JS...please!
See if this works the way you expected it to.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SimpleCustomer</title>
<script type="text/javascript">
function calcPay(hours, rate){
var regTime = 40;
var overTime = 1.5;
var calcPay;
if (hours > regTime)
calcPay = regTime * rate + ((hours - regTime) * (overTime * rate));
else
calcPay = hours * rate;
return calcPay.toFixed()
}
function adjCalcPay(calcPay){
var fedTaxes = 0.31;
var stateTaxes = 0.08;
var localTaxes = 0.02;
var takeHome = calcPay - ((calcPay * fedTaxes) + (calcPay * stateTaxes) + (calcPay * localTaxes));
return takeHome.toFixed()
}
</script>
</head>
<body>
<h1>SimpleCustomer test</h1>
<script type="text/javascript">
var hours = prompt("Enter hours worked","");
var rate = prompt("Enter hourly rate","");
var calcPay;
var takeHome;
calcPay = calcPay(hours, rate);
takeHome = adjCalcPay(calcPay);
document.writeln("Gross pay after working " + hours + " hours with pay rate of $" + rate + " per hour, will be $" + calcPay + ".");
document.writeln("<br />");
document.writeln("Take home pay after working " + hours + " hours with pay rate of $" + rate + " per hour, will be $" + takeHome + " after taxes.");
</script>
</body>
</html>
The main fix in the code is this line
takeHome = adjCalcPay(calcPay);
You had
takeHome = adjCalcPay(fedTaxes, stateTaxes, localTaxes);
The problem there is the adjCalcPay function is expecting a single parameter (the pay amount) but you are trying to pass the tax rates instead.
I also did a slight adjustment to the way you are doing the pay calculation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|