Question: Please look at the code highlighted below and suggest a correction that would allow the firstName and lastName fields to concatenate in the Employee Name
Please look at the code highlighted below and suggest a correction that would allow the firstName and lastName fields to concatenate in the "Employee Name" field.
Also, please help me understand the correct syntax for ADDING the FICA, State and Federal tax fields together, instead of concatenating.
Please see screenshot below.
function calculate(){
//This expression checks for a
if(document.theForm.firstName.value == "" || document.theForm.lastName.value == "")
alert("Both FIRST and LAST names are required.");
else firstName && lastName;
//Field for entering hours worked, 40 hours and under.
if(document.theForm.regHours.value 40)
alert("Please enter Regular Hours number between 1-40.")
else
regHours = document.theForm.regHours.value;
// Field for entering hour worked, over 40 hours.
if(document.theForm.overHours.value 40)
alert("Please enter Overtime Hours number between 0-40.")
else
overHours = document.theForm.overHours.value;
//Field for entering an hour rate.
if(document.theForm.hourlyRate.value 99.99)
alert("Please enter a valid Hourly Rate.");
else
hourlyRate = document.theForm.hourlyRate.value;
//Determines the regular pay.
if(hourlyRate && regHours)
regPay = document.getElementById('regPay').value = regHours * hourlyRate;
//Determines the overtime pay.
if(overHours && regHours && hourlyRate)
overtimePay = document.getElementById('overtimePay').value = (overHours * (hourlyRate * 1.5));
//Determines the gross pay. (regularPay + overtimePay)
if(regPay > 0)
grosspay = document.getElementById('grossPay').value = regPay + overtimePay;
//Field for entering the FICA tax rate.
if(document.theForm.fica.value
alert("Please enter a valid FICA Tax Rate");
else
fica = document.theForm.fica.value;
//Field for entering the state tax rate.
if(document.theForm.stateRate.value
alert("Please enter a valid State Tax Rate above zero.");
else
stateRate = document.theForm.stateRate.value;
//Field for entering the federal tax rate.
if(document.theForm.fedRate.value
alert("Please enter a valid Federal Tax Rate above zero.");
else
fedRate = document.theForm.fedRate.value;
//Field for entering the combined tax obligation.
if(fica && stateRate && fedRate)
totalTax = document.getElementById('totalTax').value = fica + stateRate + fedRate;
else
alert("One of the tax rates is incorrect.");
//Supposed to combine the workers' first and the last names.
if(firstName && lastName)
empName = document.getElementById('empName').value = firstName.concat(lastName);
else
alert("Something went wrong.");
//Calulate the 'take home' pay.
if(grossPay
alert("There's a problem with one of the previous fields.")
else
netPay = document.getElementById('netPay').value = grossPay + totalTax;
}

First Name john Last Name doe Regular Hours Worked (between 1-40) 10 Overtime Hours (between 0-40) 2 Hourly Rate (between 0 - 99.99) 10 Regular Pay 100 Overtime Pay 30 Gross Pay 130 FICA Tax Rate (Ex: 5.65) 2 State Tax Rate (Ex: 5.75) 3 Federal Tax Rate (Ex: 28.00) 4.0 Total Taxes 234.(0 Net Pay Calculate
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
