Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Homework help

  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Thanked 0 Times in 0 Posts

    Homework help

    Hi all i running into a bit of a problem on a homework assignment..
    program works fine but i have to figure out how to get the totals of,

    As you can see i just have it hard coded as of now.. Just not sure where to begin on adding these up

    This is what the output looks like

    //setup global var
    var employeeNumber;
    var employeeName;
    var hourlyWage;
    var hoursWorked;
    var grossPay;
    var withholdAmount;
    var records;
    var netPay;
    var totalGrossAmount;
    var totalNetPay;
    var averageNetPay;
    //create function for gross pay
    function getGrossPay() {
        if (hoursWorked >= 35) {
            grossPay = (hourlyWage * 35) + ((hourlyWage * 1.5) * (hoursWorked - 35));
        } else {
            grossPay = hourlyWage * hoursWorked;
    //create function for withhold amount
    function getWithholdAmount() {
        withholdAmount = grossPay * .15;
        withholdAmount = parseFloat(withholdAmount.toFixed(2))
    //create function for net pay
    function getNetPay() {
        netPay = grossPay - withholdAmount;
    //create function for total amounts
    //couldnt figure out how to make program add them up instead of me?
    function totalAmounts() {
        totalGrossAmount = 31796.25;
        totalNetPay = 27026.8;
        averageNetPay = 818.98;
    function employeePayrollRecords() {
        // Open the Employee Payroll Records and make them
        // available to the script
        records = openEmployeePayrollRecords();
        // Read the next record, test to see if there
        // is a next record and then output it
        while (records.readNextRecord()) {
            employeeNumber = records.getEmployeeNumber();
            employeeName = records.getEmployeeName();
            hourlyWage = records.getEmployeeHourlyWage();
            hoursWorked = records.getEmployeeHoursWorked();
            document.write(employeeNumber + "\t" 
            	+ employeeName + "\t" + grossPay + "\t" 
            	+ withholdAmount + "\t" + "      " + netPay + "<br />");
    //display to webpage
    function project4Part2() {
        document.write("Employee Employee       Gross   Withholding   Net<br />");
        document.write("Number   Name           Pay     Amount        Pay<br />");
        document.write("<br />Total Gross Payroll: "
        	    + totalGrossAmount + "<br />Total Net Payroll: " 
        	    + totalNetPay + "<br />Average Net Pay: " + averageNetPay);

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,530 Times in 2,508 Posts
    It might help if you showed your HTML. I understand that you want to make grand totals for multiple employees combined.

    // Open the Employee Payroll Records and make them available to the script

    JavaScript running in a browser is a client-side language. JavaScript does not have any commands for reading or writing files. Modern browsers can read files on the server only using an Ajax call.

    If you want to make calculations for multiple employees you need to set up a loop to input the data for each employee, and store that data in an array. Then it is simple to add up the totals of each array.

    Be aware that all that data will be lost when the program ends unless it is sent to a server-side script and stored in a database.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 04-14-2013 at 12:40 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts