Payroll Determination

[Total: 0    Average: 0/5]

This shows how to have javascript use prompts to determine a companies payroll.

Body Code:

<script language="javascript"> 
<!-- 
var numberofemployees, 
numberofpaychecks, 
counter, 
employeename, 
employeehoursworked, 
employeepayablehours, 
employeepayperhour, 
employeehourlypay, 
overtime, 
overtimehours, 
employeeovertimepay, 
overtimepay, 
totalpayroll; 

numberofpaychecks=numberofemployees=parseInt(window.prompt("enter total number of employees to be paid:","0"));

counter=numberofpaychecks 
employeeweeklypay=0 
totalpayroll=0 

while(counter>0) 
{ 

employeename=window.prompt("enter employee name:",""); 

employeepayablehours=employeehoursworked=parseInt(window.prompt("enter number of hours employee worked:","40"));
employeehourlypay=employeepayperhours=parseInt(window.prompt("enter employees hourly pay:","6"));
overtimepay=employeeovertimepay=parseInt(employeehourlypay*1.5);


overtimehours=overtime=parseInt(employeepayablehours-40);

if (overtimehours > 0) 
{ 
employeeweeklypay=parseInt(employeepayablehours*employeehourlypay+overtimehours*employeeovertimepay);
document.write("<b>OT:</b>"); 
} 
else
{ 
employeeweeklypay=parseInt(employeepayablehours*employeehourlypay);
} 
totalpayroll+=employeeweeklypay; 

document.write(employeename+" has earned $"+employeeweeklypay+" this week.<br />"); 
counter--;
} 

document.write("<h3>Total weekly payroll is $"+totalpayroll+"."); 
--> 
</script>

Times Viewed: 3

Leave a Reply

Your email address will not be published. Required fields are marked *