Question
Paycheck Version 2 Calculator The user inputs First Name, Last Name, Hours Worked, Hourly Pay Rate, FICA, State, and Federal Tax Rates. The application calculates
Paycheck Version 2 Calculator
The user inputs First Name, Last Name, Hours Worked, Hourly Pay Rate, FICA, State, and Federal Tax Rates. The application calculates and displays the Regular Hours, Overtime Hours, Regular Pay, Overtime Pay, Gross Pay, Total Taxes, and Net Pay. The application also performs the following user entry validation tests: 1. Ensure that Hours Worked is entered and is between 0 and 80. 2. Ensure that Hourly Pay Rate is entered and is between 0 and 100.00. If both of the above conditions are not met, an error message alert window appears that says the following: Please enter valid hours and a valid payrate! Because the user isnt entering Regular Hours and Overtime Hours as with the first paycheck assignment, you must use an If statement to test Hours Worked to calculate Regular Hours and OverTime Hours and Regular Pay and Overtime Pay. All Hours Worked over 40 are considered Overtime Hours while Hours Worked between 0 and 40 are considered Regular Hours. Regular Pay is calculated as Regular Hours worked * Hourly Pay Rate. Overtime Pay is calculate as Overtime Hours * Hourly Rate * 1.5. The following screenshots demonstrate how the application works:
1. Create an HTML5 file that contains a HTML form like the screenshots shown above that accepts the First Name, Last Name, Hours Worked, Hourly Rate, Fica Tax Rate, State Tax Rate, and Federal Tax Rate for entry and shows the Regular Hours Worked, Overtime Hours Worked, Regular Pay, Overtime Pay, Gross Pay, Total Taxes, Employee Name, and Net Pay and a submit button with the label Calculate. Save the file as paycheck2.html and store it in your Ch05directory. The paycheck2.html file must be free of errors and validated. Add the necessary code to link to a CSS file called styles.css that is stored in your Ch05/css subdirectory. Add the necessary code to use the paycheck2.js file that is stored in your Ch05/js subdirectory.
2. Download the styles.css file and store it in your Ch05/css subdirectory.
3. Create and debug a JavaScript file that processes the Paycheck information from the paycheck.html file that meets the following specifications (43 Points Total as broken down below):
a. Save the file as paycheck2.js in your Ch05/js subdirectory. (1 Point)
b. Create a function that is called when the paycheck2.html form is submitted. The function must include the following information. (3 Points)
c. Output variables for the Regular Hours, Overtime Hours, Regular Pay, Overtime Pay, Gross Pay, Total Taxes, Net Pay, and Employee Name return results to the paycheck2.html file. (2 Points)
d. Input variables for the First Name, Last Name, Hours Worked, Hourly Rate, Fica Tax, State Tax, and Federal Tax use the document.getElementByID method to retrieve input from the paycheck2.html file). (2 Points)
e. An if then else statement will be used to ensure that Hours Worked is entered and is between 0 and 80 and that Hourly Pay Rate is entered and is between 0 and 100.00. If both of the above conditions are not met, an error message alert window appears that says the following: Please enter valid hours and a valid payrate! (10 Points)
f. An if then else statement will be used to determine Regular Hours and Overtime Hours wherein Hours Worked over 40 are Overtime Hours and Hours Worked between 0 and 40 are Regular Hours. (10 Points)
g. Regular Pay will be correctly calculated and formatted with the toFixed() method. (2 Points)
h. Overtime Pay will be correctly calculated and formatted with the toFixed() method. (2 Points)
i. Gross Pay will be correctly calculated and formatted with the toFixed() method. (2 Points)
j. Fica Tax deducted will be correctly calculated. (1 Point)
k. State Tax deducted will be correctly calculated. (1 Point)
l. Federal Tax deducted will be correctly calculated. (1 Point)
m. Total Taxes will be correctly calculated and formatted. (2 Points)
n. The Employee Name will be correctly displayed. (1 Point)
o. The Net Pay will be correctly calculated and formatted with the toFixed() method. (2 Points)
p. The init() function will be correctly used. (1 Point)
This is how I was doing.
function calculate(){ 'use strict'; // Get variables from form 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 rate = document.getElementById('rate').value; var fICA = document.getElementById('fICA').value; var stateTax = document.getElementById('stateTax').value; var fedTax = document.getElementById('fedTax').value; // Make calculations var regPay = (rate*regHours).toFixed(2); var overtimePay = (overHours*(1.5*rate)).toFixed(2); var grossPay = (+regPay+ +overtimePay).toFixed(2); var taxes = ((+fICA+ +stateTax+ +fedTax)/100*grossPay).toFixed(2); var netPay = (grossPay-taxes).toFixed(2); var employeeName = lastName+", "+firstName; // Insert new values document.getElementById('regPay').value = regPay; document.getElementById('overtimePay').value = overtimePay; document.getElementById('grossPay').value = grossPay; document.getElementById('totalTax').value = taxes; document.getElementById('employeeName').value = employeeName; document.getElementById('netPay').value = netPay; return false; }
function init(){ 'use strict'; document.getElementById('form').onsubmit = calculate; }
window.onload = init;
// From: http://www.assemblesoft.com/examples/form/simpleform.html * {margin:0; padding:0;}
html { font: 90%/1.3 arial,sans-serif; padding:1em; background:#B9C2CC; } form { background:#fff; padding:1em; border:1px solid #eee; }
fieldset div { margin:0.3em 0; clear:both; }
form { margin:1em; width:15em; }
label { float:none; width:12em; display:block; clear:both; }
legend { color:#0b77b7; font-size:1.4em; } legend span { width:10em; text-align:right; } input { padding:0.15em; width:10em; border:1px solid #ddd; background:#fafafa; font:bold 1em arial, sans-serif; -moz-border-radius:0.4em; -khtml-border-radius:0.4em; display:block; float:left; } input:hover, input:focus { border-color:#c5c5c5; background:#f6f6f6; } fieldset { border:1px solid #ddd; padding:0 0.5em 0.5em; } .date input { background-image:url(../gfx/calendar-small.gif); background-repeat:no-repeat; background-position:100% 50%; }
.date fieldset label { float:none; display:block; text-align:left; width:auto; } .date fieldset div { float:left; clear:none; margin-right:0.2em; } .radio, .date { position:relative; } .radio fieldset, .date fieldset { border:none; width:auto; padding:1px 0 0 11em; } .radio legend, .date legend { font-size:1em; color:#000; } .radio legend span, .date legend span { position:absolute; left:0; top:0.3em; width:10em; display:block; } .radio label, .radio input { vertical-align:middle; display:inline; float:none; width:auto; background:none; border:none; } .radio div { float:left; white-space:nowrap; clear:none; }
.email { width:14em; }
input.default { color:#bbb; }
#submit { margin:1em; width:69px; height:26px; overflow:hidden; border:0; display:block; cursor:pointer !important; cursor:hand; } #submit:hover { background-position:0 -26px; }
textarea { padding:0.15em; width: 200px; height: 50px; display: block; }
.error { color: ##FF1400; } /* :invalid { color:red; } */ /* input[type=checkbox], input[type=radio] { visibility: hidden; width:0; height:0; padding:0; margin:0; } input[type=checkbox] + label, input[type=radio] + label { padding-left:18px; } input[type=checkbox] + label{ background: url(../gfx/check_radio.png) 0 0 no-repeat; } input[type=checkbox]:focus + label{ background-position: 0 -16px; } input[type=checkbox] + label:hover{ background-position: 0 -32px; } input[type=checkbox]:checked + label{ background-position: 0 -48px; }
input[type=radio] + label{ background: url(../gfx/check_radio.png) 0 -64px no-repeat; } input[type=radio]:focus + label{ background-position: 0 -80px; } input[type=radio] + label:hover{ background-position: 0 -96px; } input[type=radio]:checked + label{ background-position: 0 -112px; } */
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