Jump to content
Larry Ullman's Book Forums

John B

Members
  • Posts

    13
  • Joined

  • Last visited

Everything posted by John B

  1. Never mind I got the problem solved, I had to remove the <?php, ?> tags and now it looks exactly like figure A. Thanks for the help HartleySan and Larry Ullamn.
  2. I got the link to work and the text to appear but when the site opens I get the PHP Version 7.1.8 screen that lists the system, build date, etc when all I want is the text "this is the standard html" like in the figure A example on pg 4
  3. My first.php file is stored in a folder called ch01 the path to it is xampp/htdocs/ch01 and I had Apache running when I tried entering the http://localhost/first.php for the script but I still get the 404 error
  4. Hi Larry Ullman, I'm having some trouble on pg 4 step 6 where I run the first.php file. Whenever I run the file using the link http://localhost/first.php I end up getting an error message saying Object not found followed by error 404. Do you have any advice on what I should do. I also stored my first.php file in xampp/htdocs/ch01.
  5. Hi HartleySan, I have been working on this problem and I'm still having trouble. I read your last message about getting NaN when you do number math with strings and what I've been doing so far is trying to convert parts of my if then else statements to strings like regularPay, overtimePay without using number math but I still can't get regualrPay, overtimePay, and the other form values to display correctly when I submit the form. Currently the assignment wants me to use an If statement to test Hours Worked to calculate regularHours and overtimeHours and regularPay and overtimePay. All hours worked over 40 are considered Overtime Hours while hours worked between 0 and 40 are considered regular hours. As with the previous assignment, regularPay is calculated as regularHours worked * hourlypayRate. overtimePay is calculate as overtimeHours * hourlyRate * 1.5. All of the remaining grossPay, totalTaxes, and netPay variables are calculated as with the previous assignment. Lastly I'd appreciate it if you showed me an example of creating a string without number math, my code is posted down below and I appreciate any help on helping solve this problem. function calculate() { 'use strict'; var regularPay = parseFloat(regularHours*hourlyRate).toFixed(2); var overtimePay = parseFloat(overtimeHours*(hourlyRate*1.5)).toFixed(2); var hoursWorked = document.getElementById('hoursWorked').value; var regularHours = document.getElementById('regularHours').value; var overtimeHours = document.getElementById('overtimeHours').value; var hourlyRate = document.getElementById('hourlyRate').value; var ficaTax = document.getElementById('ficaTax').value; var stateTax = document.getElementById('stateTax').value; var federalTax = document.getElementById('federalTax').value; var grossPay = document.getElementById ('grossPay').value = parseFloat(+regularPay+ +overtimePay).toFixed(2); var totalTaxes = document.getElementById ('totalTaxes').value = parseFloat(+ficaTax+ +stateTax+ +federalTax)* grossPay /100 .toFixed(2); var netPay = document.getElementById ('netPay').value = parseFloat(grossPay-totalTaxes).toFixed(2); var employeeName; var firstName = document.getElementById('firstName').value; var lastName = document.getElementById('lastName').value; employeeName = firstName + ' ' + lastName; document.getElementById('employeeName').value = employeeName; if ( (hoursWorked >= 0 && hoursWorked <= 80 && hourlyRate >= 0 && hourlyRate <= 100) ) { } else { // Show an error: alert('Please enter valid hours and a valid payrate!'); } if ( (hoursWorked >= 40) ) { document.getElementById('overtimeHours').value; // display overtimeHours: } else if ( (hoursWorked >= 0 && hoursWorked <= 40) ) document.getElementById('regularHours').value; { // display regularHours: return false; } // end of else } // End of function. function init() { 'use strict'; document.getElementById('form1').onsubmit = calculate; } // End of init() function. window.onload = init;
  6. Hi HartleySan thanks for replying to my post. I have been recently updating my code and it seems like I got some things to work but there are other parts of the assignment I'm still having trouble with. You may have read in my previous post that I had trouble displaying the error message for when invalid values were entered, I updated my code so now whenever I type an invalid value my paycheck calculator displays the error message like it should. I also found it helpful to create my if then else statement after declaring my variables. Where I'm having trouble now is in Step 3 f where the assignment asks me to create an if then else statement to determine regularHours and overtimeHours wherein Hours Worked over 40 are Overtime Hours and Hours Worked between 0 and 40 are Regular Hours. In addition to this when I press the submit button on my calculator the form values for grossPay, totalTaxes, and netPay all display NaN. I have posted my code down below, I believe the reason my code isn't working is because there might be a syntax error or logical error in my if then else statement and if that's the case I may need to figure out how to rewrite my if then else statement. Thank you once again for responding to my post and any help is appreciated. function calculate() { 'use strict'; var regularPay var overtimePay var hoursWorked = document.getElementById('hoursWorked').value; var regularHours = document.getElementById('regularHours').value; var overtimeHours = document.getElementById('overtimeHours').value; var hourlyRate = document.getElementById('hourlyRate').value; var ficaTax = document.getElementById('ficaTax').value; var stateTax = document.getElementById('stateTax').value; var federalTax = document.getElementById('federalTax').value; var grossPay = document.getElementById ('grossPay').value = parseFloat(+regularPay+ +overtimePay).toFixed(2); var totalTaxes = document.getElementById ('totalTaxes').value = parseFloat(+ficaTax+ +stateTax+ +federalTax)* grossPay /100 .toFixed(2); var netPay = document.getElementById ('netPay').value = parseFloat(grossPay-totalTaxes).toFixed(2); var employeeName; var firstName = document.getElementById('firstName').value; var lastName = document.getElementById('lastName').value; employeeName = firstName + ' ' + lastName; document.getElementById('employeeName').value = employeeName; if ( (hoursWorked >= 0 && hoursWorked <= 80 && hourlyRate >= 0 && hourlyRate <= 100) ) { } else { // Show an error: alert('Please enter valid hours and a valid payrate!'); } if ( (hoursWorked > 40) ) { document.getElementById('overtimePay').value = parseFloat(overtimeHours*(hourlyRate*1.5)).toFixed(2); // display overtimeHours: } else if ( (hoursWorked >= 0 && hoursWorked <= 40) ) document.getElementById('regularPay').value = parseFloat(regularHours*hourlyRate).toFixed(2); { // display regularHours: return false; } // end of else } // End of function. function init() { 'use strict'; document.getElementById('form1').onsubmit = calculate; } // End of init() function. window.onload = init;
  7. Hi everyone, I'm currently working on an assignment for my class that involves me creating a calculator and displaying certain form values with if then else statements. I attached a file to the assignment I'm working on below. So far my problem with this assignment is in ("Step 3, e") this step in the assignment requires me to create an if then else statement for hoursWorked between 0 and 80 and hourlyRate between 0 and 100. The next part of this assignment tells me if the conditions aren't met I must provide an error message, here is where I encountered problems in this assignment. When working on this assignment I got my error message to display but not in the right place, the error message is supposed to appear only during invalid data tests instead, the error message appears every time I click the submit button which I don't want it to do. I think the problem has to do with how I'm writing my if statement and I would appreciate it if anyone could look over my code and give me advice on how to display the error message properly, my code is listed down below. function calculate() { 'use strict'; var hoursWorked = document.getElementById('hoursWorked').value; if (hoursWorked.value <= 80 && hourlyRate.value <= 100) { } else { // Show an error: alert('Please enter valid hours and a valid payrate!'); } var regularHours = document.getElementById('regularHours').value; var overtimeHours = document.getElementById('overtimeHours').value; var hourlyRate = document.getElementById('hourlyRate').value; var ficaTax = document.getElementById('ficaTax').value; var stateTax = document.getElementById('stateTax').value; var federalTax = document.getElementById('federalTax').value; var regularPay = document.getElementById ('regularPay').value = parseFloat(regularHours*hourlyRate).toFixed(2); var overtimePay = document.getElementById ('overtimePay').value = parseFloat(overtimeHours*(hourlyRate*1.5)).toFixed(2); var grossPay = document.getElementById ('grossPay').value = parseFloat(+regularPay+ +overtimePay).toFixed(2); var totalTaxes = document.getElementById ('totalTaxes').value = parseFloat(+ficaTax+ +stateTax+ +federalTax)* grossPay /100 .toFixed(2); var netPay = document.getElementById ('netPay').value = parseFloat(grossPay-totalTaxes).toFixed(2); var employeeName; var firstName = document.getElementById('firstName').value; var lastName = document.getElementById('lastName').value; employeeName = firstName + ' ' + lastName; document.getElementById('employeeName').value = employeeName; return false; } // End of function. function init() { 'use strict'; document.getElementById('form1').onsubmit = calculate; } // End of init() function. window.onload = init; Paycheck2(1).pdf
  8. Hi HartleySan, I have some good news regarding my code. Recently I have been rewriting some of my equations for grossPay, netPay, totalTaxes etc and after testing the code in my paycheck calculator in Firefox it's safe to say I have my code and the paycheck calculator working, all I had to do was observe how you rewrote my code in your previous reply and I eventually did my best to rewrite my equations as I saw fit until I got the code working. Here is my newly updated code and the paycheck calculator is working as it should, thank you for all your all help and to responding to my messages. function calculate() { 'use strict'; var regularHours = document.getElementById('regularHours').value; var overtimeHours = document.getElementById('overtimeHours').value; var hourlyRate = document.getElementById('hourlyRate').value; var ficaTax = document.getElementById('ficaTax').value; var stateTax = document.getElementById('stateTax').value; var federalTax = document.getElementById('federalTax').value; var regularPay = document.getElementById ('regularPay').value = parseFloat(regularHours*hourlyRate).toFixed(2); var overtimePay = document.getElementById ('overtimePay').value = parseFloat(overtimeHours*(hourlyRate*1.5)).toFixed(2); var grossPay = document.getElementById ('grossPay').value = parseFloat(+regularPay+ +overtimePay).toFixed(2); var totalTaxes = document.getElementById ('totalTaxes').value = parseFloat(+ficaTax+ +stateTax+ +federalTax)* grossPay /100 .toFixed(2); var netPay = document.getElementById ('netPay').value = parseFloat(grossPay-totalTaxes).toFixed(2); var employeeName; var firstName = document.getElementById('firstName').value; var lastName = document.getElementById('lastName').value; employeeName = firstName + ' ' + lastName; document.getElementById('employeeName').value = employeeName; return false; } // End of function. function init() { 'use strict'; document.getElementById('form1').onsubmit = calculate; } // End of init() function. window.onload = init;
  9. Thank you for trying I tested my paycheck.html file in Chrome and seems I got the error to appear in my browser console, here is a screenshot showing the error. I think what I will do is test my page in different browsers for errors and try to reorganize my code better, not only that but I will review how you rewrote my code and see if I can write my equations better using parseFloat in order to get the values to appear.
  10. Hi HartleySan I have another question, I think I am having an issue when it comes to the browser console I am able to pull it up through the Mozilla Firefox menu and then by going to the web developer menu but when I pull up the browser console it doesn't show me the list of errors in my code. I posted an attachment of what it looks like when I pull my browser console in Firefox.
  11. Hi HartleySan I recently made some changes to my code in Notepad++. So far I tried using the parseFloat function that way the values for regularPay, overtimePay and the other values I had would come out as decimals instead of strings but now, it seems like nothing is calculating when it did before and I can't get the values for grossPay, totalTaxes, and netPay to appear either. Here is my code below I have my equations set up as well the parseFloat function for each of my values but I still don't know why nothing is appearing when it should, do you think it has something to do with the way i'm writing the parseFloat function in my equations? function calculate() { 'use strict'; var regularHours = document.getElementById('regularHours').value; var overtimeHours = document.getElementById('overtimeHours').value; var hourlyRate = document.getElementById('hourlyRate').value; var ficaTax = document.getElementById('ficaTax').value; var stateTax = document.getElementById('stateTax').value; var federalTax = document.getElementById('federalTax').value; var regularPay = document.getElementById ('regularPay').value = parseFloat(regularHours*hourlyRate).toFixed(2); var overtimePay = document.getElementById ('overtimePay').value = parseFloat(overtimeHours*(hourlyRate*1.5)).toFixed(2); var grossPay = document.getElementById ('grossPay').value = parseFloat(regularPay+overtimePay).toFixed(2); var totalTaxes = document.getElementById ('totalTaxes').value = parseFloat(ficaTax+stateTax+federalTax*grossPay)/100.toFixed(2); var netPay = document.getElementById ('netPay').value = parseFloat(grossPay-totalTaxes).toFixed(2); var employeeName; var firstName = document.getElementById('firstName').value; var lastName = document.getElementById('lastName').value; employeeName = lastName + ', ' + firstName; document.getElementById('employeeName').value = employeeName; return false; } // End of function. function init() { 'use strict'; document.getElementById('form1').onsubmit = calculate; } // End of init() function. window.onload = init;
  12. Hi HartleySan, thank you for responding to my question. I think I understand what your trying to tell me based on your reply, in my code both regularPay and overtimePay are presented as strings instead of numbers but my question is how do I convert regularPay and overtimePay into a number? Also, when regularPay and overtimePay are converted into numbers will the values for regularPay and overtimePay still appear in the calculator when I test the code?
  13. Hi Larry Ullman, I’m new to JavaScript and I’m currently working on an assignment for my class that involves me to create a paycheck calculator based on a form I created using Html elements in Notepad++ and elements of JavaScript in a separate Notepad++ document. The form I’m creating uses many aspects presented in chapter 4 of the Modern JavaScript Develop and Design textbook. The problem I’m having with my code is (posted below), so far when creating the paycheck calculator, I’ve got the regularPay and the overtimePay to calculate correctly but my main problem is whenever I try to get the calculations for the grossPay, netPay, and totalTaxes to calculate they won’t work at all. I would appreciate it if you looked over my code and gave me feedback on how to get the values to display. Here is my code for the Html form and below it is the JavaScript code. Here is the link to the assignment I’m working on as well. Assignment Link https://docs.google.com/file/d/0BwDHF5mNxWWZQm1aRkpCbUFkdkE/edit Html <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Paycheck Calculator</title> <link rel="stylesheet" href="css/styles.css"> </head> <body> <form action="#" method="post" id="form1"> <fieldset> <div><label for="firstName">First Name</label><input type="text" name="firstName" id="firstName" required></div> <div><label for="lastName">Last Name</label><input type="text" name="lastName" id="lastName" required></div> <div><label for="regularHours">Regular Hours Worked (between 0 and 40)</label><input type="text" name="regularHours" id="regularHours" value="0" required></div> <div><label for="overtimeHours">Overtime Hours Worked (between 0 and 40)</label><input type="text" name="overtimeHours" id="overtimeHours" value="0" required></div> <div><label for="hourlyRate">Hourly Rate (between 0 and 99.99)</label><input type="text" name="hourlyRate" id="hourlyRate" value="0.00" required></div> <div><label for="ficaTax">Fica Tax Rate (ex. 5.65)</label><input type="text" name="ficaTax" id="ficaTax" value="0.00" required></div> <div><label for="stateTax">State Tax Rate(ex. 28.00)</label><input type="text" name="stateTax" id="stateTax" value="0.00" required></div> <div><label for="federalTax">Federal Tax Rate (ex. 5.75)</label><input type="text" name="federalTax" id="federalTax" value="0.00" required></div> <div><label for="regularPay">Regular Pay</label><input type="text" name="regularPay" id="regularPay" value="0.00"></div> <div><label for="overtimePay">Overtime Pay</label><input type="text" name="overtimePay" id="overtimePay" value="0.00"></div> <div><label for="grossPay">Gross Pay</label><input type="text" name="grossPay" id="grossPay" value="0.00"></div> <div><label for="totalTaxes">Total Taxes</label><input type="text" name="totalTaxes" id="totalTaxes" value="0.00"></div> <div><label for="employeeName">Employee Name</label><input type="text" name="employeeName" id="employeeName"></div> <div><label for="netPay">Net Pay</label><input type="text" name="netPay" id="netPay" value="0.00"></div> <div><input type="submit" value="Calculate" id="submit"></div> </fieldset> </form> <script src="js/paycheck.js"></script> </body> </html> JavaScript function calculate() { 'use strict'; var regularHours = document.getElementById('regularHours').value; var overtimeHours = document.getElementById('overtimeHours').value; var hourlyRate = document.getElementById('hourlyRate').value; var ficaTax = document.getElementById('ficaTax').value; var stateTax = document.getElementById('stateTax').value; var federalTax = document.getElementById('federalTax').value; var regularPay = document.getElementById('regularPay').value = (regularHours*hourlyRate).toFixed(2); var overtimePay = document.getElementById('overtimePay').value = (overtimeHours*(hourlyRate*1.5)).toFixed(2); /*var grossPay = document.getElementById('grossPay').value = (regularPay+overtimePay).toFixed(2); var totalTaxes = document.getElementById('totalTaxes').value = (ficaTax+stateTax+federalTax*grossPay/100).toFixed(2); var netPay = document.getElementById('netPay').value = (grossPay-totalTaxes).toFixed(2); */ var employeeName; var firstName = document.getElementById('firstName').value; var lastName = document.getElementById('lastName').value; employeeName = lastName + ', ' + firstName; document.getElementById('employeeName').value = employeeName; return false; } // End of function. function init() { 'use strict'; document.getElementById('form1').onsubmit = calculate; } // End of init() function. window.onload = init;
×
×
  • Create New...