Question
I am looking for suggestions on fixing the code listed below. There is HTML and JS, in addition to a screenshot of the form I
I am looking for suggestions on fixing the code listed below. There is HTML and JS, in addition to a screenshot of the form I am trying to populate. I have not been able to get the calculations to run. I would appreciate help on figuring out what the problem is.
HTML
JS
function calculate() {
'use strict';
var netPay;
var firstName = document.getElementById('firstName').value;
var lastName = document.getElementById('lastName').value;
var regHours = document.getElementById('regHours').value;
var overHours = document.getElementById('overHours').value;
var hourlyRate = document.getElementById('hourlyRate').value;
var regPay = document.getElementById('regPay').value;
var overtimePay = document.getElementById('overtimePay').value;
var grossPay = document.getElementById('grossPay').value;
var fica = document.getElementById('fica').value;
var stateRate = document.getElementById('stateRate').value;
var fedRate = document.getElementById('fedRate').value;
var totalTax = document.getElementById('totalTax').value;
var empName = document.getElementById('empName').value;
var netPay = document.getElementById('netPay').value;
//Calculates a worker's regular pay.
if(regHours > 0 && regHours
regPay = regHours * hourlyRate;
}
document.getElementById('regPay').value = '$' + regPay.toFixed(2);
else { // An error:
document.getElementById('regPay').value = 'Please enter valid values.';
}
//Calculates a worker's overtime pay.
if(overHours >= 0 && overHours
{
overtimePay = overHours * 1.5;
}
else if
{
document.getElementById('overHours').value = 'Please enter valid values.';
}
//Calculate's a worker's gross pay.
if(regPay && overtimePay){
grossPay = regPay + overtimePay;
}
else
{
document.getElementById('grossPay').value = 'That does not compute.';
}
//Calculate worker's total tax oblication.
if(fica > 0 && fice
var ficaTax = grossPay * fica;
}
else{
document.getElementById('fica').value = 'Rate must be greater than 0 and less than 100.';
}
if(stateRate > 0 && stateRate
var stateTax = grossPay * stateRate;
}
else{
document.getElementById('stateRate').value = 'Rate must be greater than 0 and less than 100.';
}
if(fedRate > 0 && fedRate
var fedTax = grossPay * fedRate;
}
else{
document.getElementById('fedRate').value = 'Rate must be greater than 0 and less than 100.';
}
totalTax = ficaTax + stateTax + fedTax;
// Calculate a worker's net pay.
netPay = grossPay - totalTax;
// Concatentate worker's first and last names.
empName = firstName + lastName;
var result=document.getElementById('result')
result.innerHTML=netPay;
var newcontent = document.createElement('div');
newcontent.innerHTML = "bar"+ netPay;
return false;
// Function called when the window has been loaded.
// Function needs to add an event listener to the form.
function init() {
'use strict';
// Add an event listener to the form:
var theForm = document.getElementById('theForm');
theForm.onsubmit = calculate;
} // End of init() function.
// Assign an event listener to the window's load event:
window.onload = init;
Paycheclk First Name Last Name Regular Hours Worked (between 0-40) Overtime Hours (between 0-40) Hourly Rate (between 0 99.99) Regular Pay Overtime Pay Gross Pay FICA Tax Rate (Ex: 5.65) State Tax Rate (Ex: 5.75) Federal Tax Rate (Ex: 28.00) Total Taxes Employee Name Net Pay Calculate
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started