This is all basic Javascript stuff, it’s my introductory class but the lecturer doesn’t really lecture about what we need to learn about so I’m stuck on what I need to do on the next few labs.
Here is lab 3 that I have completed and working (it’s a payroll calculator, will process the payroll of something for a given amount of hours and payrate):
[CODE]<HTML>
<script language=”JavaScript”>
// Payroll Processing Program by Sprrr – – – – payroll2.html
// Variables
document.writeln(‘Welcome to the online payroll processing program’);
document.writeln();
go_on = ‘Y’
empname = prompt(‘Enter any employee name’,”);
function do_calc()
{
if (hours > 40) total_pay = 40 * payrate + (hours – 40) * payrate * 1.5;
if (hours <= 40) total_pay = hours*payrate;
}
function do_display()
{
document.writeln(‘The Payroll for: ‘,empname,'<P>’);
document.writeln(‘Payrate: ‘,payrate,'<BR>’);
document.writeln(‘Hours Worked: ‘,hours,'<BR>’);
document.writeln(‘Total Pay: ‘,total_pay);
go_on = prompt(‘Do you want to process another employee? Y or N’,’Y’);
if (go_on == ‘Y’) empname = prompt(‘Enter any Employee Name’,”);
}
while ((empname != ”) & (go_on == ‘Y’))
{
payrate = prompt(‘Enter the Employees Payrate’,”);
hours = prompt(‘Enter the hours worked’,”);
// Payroll calculations
do_calc()
// Output
do_display()
}
</script>
</HTML>
Now for Lab 4, it says I need to modify lab 3 to include a calculation for city tax withholding and federal tax withholding.
1) City Tax flat rate 1.75%
2) Federal tax rate – use an array to store the federal tax table, use a FOR loop to calculate the tax.
I believe #1 should be a lot easier to do but I can’t seem to think of what I need to do.
Here is the code I have for lab 4 so far (I made the array to store the information):
[CODE]<HTML>
<script language=”JavaScript”>
// Payroll Processing Program by Sprrr – – – – payroll2.html
// Fed Tax Array
var fedTable = new Array(51, 0, .15
525, 71.10, .28
1125, 239.10, .31
2535, 676.20, .36
5475, 1734.60, .396);
// Variables
document.writeln(‘Welcome to the online payroll processing program’);
document.writeln();
go_on = ‘Y’
empname = prompt(‘Enter any employee name’,”);
function do_calc()
{
if (hours > 40) total_pay = 40 * payrate + (hours – 40) * payrate * 1.5;
if (hours <= 40) total_pay = hours*payrate;
}
function do_display()
{
document.writeln(‘The Payroll for: ‘,empname,'<P>’);
document.writeln(‘Payrate: ‘,payrate,'<BR>’);
document.writeln(‘Hours Worked: ‘,hours,'<BR>’);
document.writeln(‘Total Pay: ‘,total_pay);
go_on = prompt(‘Do you want to process another employee? Y or N’,’Y’);
if (go_on == ‘Y’) empname = prompt(‘Enter any Employee Name’,”);
}
while ((empname != ”) & (go_on == ‘Y’))
{
payrate = prompt(‘Enter the Employees Payrate’,”);
hours = prompt(‘Enter the hours worked’,”);
// Payroll calculations
do_calc()
// Output
do_display()
}
</script>
</HTML>
The first number in each row states that money frame they have, so for the first row, anyone that is over $51 but not over $525 (second row) will get 15% withheld.
For the rest, the middle number is a flat amount. So for row 2, it’s 28% but $71.10 withheld as well.
A HUGE thank you to anyone who can help me out, I need the lab(s) completed relatively soon but if you can spare some time to explain how you did it I would greatly appreciate that as well!