I have a code that has been completed and I am needing help trying to figure the last step to make it work correctly. My first function takes hours worked and pay rate and figures the gross wage. The second function takes the gross wage and figures all of the taxes and adds them together to get result. I need this to display only the hours worked, payrate, gross wage and the total tax. I can get everything to work except for the tax function. I need to call the function from the gross wage function and then the result of taxes sent back to first function and diplayed with all information.
Any help would be great as I have been working on this for hours and no solution yet. P.S. It has to be 2 functions.
Thanks
Html Code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Calcualte Gross Wage and Tax</title>
</head>
<body>
<script type="text/javascript" src="calculateGross.js"></script>
<script type="text/javascript" src="calculateTax.js"></script>
<table>
<tr>
<td>Hours Worked :</td>
<td><input type="text" id="hours" value="40"></td>
</tr>
<tr>
<td>Pay Per Hour :</td>
<td><input type="text" id="rate" value="15"></td>
</tr>
<tr>
<td><input type="button" value="Calculate" onclick=calculate()></td>
</tr>
</table>
<br>
</body>
</html>
Function # 1
function calculate(payRate, hours){
var hoursWorked = document.getElementById("hours").value;
var payRate = document.getElementById("rate").value;
if (hoursWorked <=40){
grossPay = (hoursWorked * payRate);
}
else {
grossPay = (payRate * 1.5) * (hoursWorked - 40) + (40 * payRate);
}
document.writeln("Hours Worked:" + " " + hoursWorked + "<br>" + "<br>");
document.writeln("Hourly Pay Rate:" + " " + payRate + "<br>" + "<br>");
document.writeln("Gross Wage:" + " " + "$" + grossPay.toFixed(2) + "<br>" + "<br>");
}
Function # 2
function calculateTax(gross) {
/*The varibles used in this function*/
var gross;
var localTax;
var localTaxBal;
var stateTax;
var stateTaxBal;
var fedTax;
var fedTaxBal;
var totalTax;
localTax = Number ( gross ) * 2/100; /* This takes the gross
amount and gets the 2% local tax amount*/
localTaxBal = Number ( gross ) - Number ( localTax ); /* This takes
the gross amount and subtracts the local tax amount to give the
new gross amount.*/
stateTax = Number ( localTaxBal ) * 8/100; /* This takes the
gross balance after local taxes and then gets the 8% state tax
amount.*/
stateTaxBal = Number ( localTaxBal ) - Number ( stateTax ); /* This
takes the gross amount left after local taxes subtracted and then
it subtracts the state tax amount to give the gross amount needed
for the federal tax.*/
fedTax = Number ( stateTaxBal ) * 31/100; /* This takes the
gross balance after the state and local taxes have been subtracted
and then figures the federal tax amount.*/
fedTaxBal = Number ( stateTaxBal ) - Number ( fedTax ); /* This
takes the gross amount left after state and local taxes subtracted
and subtracts the federal tax from the remaining gross wage.*/
totalTax = Number ( localTax.toFixed(2) ) + Number
( stateTax.toFixed(2) ) + Number ( fedTax.toFixed(2) ); /* This
takes the local, state and federal tax amounts and adds them together
to get the total taxes to be paid from gross wage. This also uses the
.toFixed(2) to round to the nearest penny and only two decimal places.*/
document.writeln("Total Taxes:" + " " + "$" + totalTax.toFixed(2) + "<br>" + "<br>");
/* This returns the final answer to the
first function which sends to the html document (total.*/
return totalTax.toFixed(2);
}