
B. Write a JavaScript program that would input Employee Name, Rate per hour, No. of hours worked and will compute the daily wage of an employee. If the number of hours worked exceeds eight hours add 30% to each excess hours as overtime rate. Formula: Daily Wage = Rate per hour * No. of hours worked + OT pay

B. Write a JavaScript program that would input Employee Name, Rate per hour, No. of hours worked and will compute the daily wage of an employee. If the number of hours worked exceeds eight hours add 30% to each excess hours as overtime rate. Formula: Daily Wage = Rate per hour * No. of hours worked + OT pay


hi Friend,
Try the following code:
<html>
<script>
function calculate(){
var name=document.form.name.value;
var ratePerHour=document.form.rate.value;
var thours=document.form.hour.value;
var wages;
var increasedWage;
var gp;
if(thours>8){
var wage=8*ratePerHour;
var wg=wage*0.30;
var hr=thours-8;
increasedWage=wg*hr;
wages=wage+increasedWage;
}
else{
wages=thours*ratePerHour;
increasedWage=0;
}
document.writeln("Employee Name: "+name+"<br>");
document.writeln("Rate Per Hour: "+ratePerHour+"<br>");
document.writeln("No. of hours: "+thours+"<br>");
document.writeln("Overtime pay: "+increasedWage+"<br>");
document.writeln("Gross pay: "+wages+"<br>");
}
</script>
<form name="form">
<table>
<tr><td>Employee Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Rate Per Hour:</td><td><input type="text" name="rate"></td></tr>
<tr><td>Number of Hours:</td><td><input type="text" name="hour"></td></tr>
<tr><td></td><td><input type="button" value="Calcuate" onclick="calculate();"></td></tr>
</table>
</form>
</html>
Thanks