Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN JAVASCRIPT/ HTML5: please provide HTML5 Code Use a one-dimensional array to s

ID: 3869223 • Letter: I

Question

IN JAVASCRIPT/ HTML5: please provide HTML5 Code

Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, if a salesperson who grosses $5000 in sales in a week receives $200 plus 9 percent of $5000, or a total of $650. Write a script (using an array of counters) that obtains the gross sales for each employee through an HTML5 form, and determines how many of the salespeople earned salaries in each of the following ranges (assume each salesperson's salary is truncated to an integer amount):

a) $200-299

b)$300-399

c)$400-499

d)$500-599

e)$600-699

f)$700-799

g)$800-899

h)$900-999

i)$1000 and over

Explanation / Answer

//sales.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Sales and Commission</title>
<script type="text/javascript">
<!--
    //call method calculateSalary that prompts user to enter sales amont and
    //find the income of the values plus 9 percent of sales
    function calculateSalary()
    {
        var i = 0; var j;
        //prompt for sales
        var string = prompt("Sales of Employee (Exit: 0):", "");
      
        var pay = parseInt(string);
        //Declare an array set to zero to count ranges
        var count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
      
        //Check if
        while (pay != 0)
        {

            //set income of type array
            var income = new Array();
            //calculate the salary 200 + 9 % of total pay
            var salary = 200.0 + Math.round(0.09 * pay);
            //set salary to income
            income[i] = salary;
            document.writeln("Sales $ ", +pay);
            document.write("<br />");
            document.writeln("Salesperson's income is $", +income[i]);
            document.write("<br />");

            if (income[i] >= 200 && income[i] <= 299)               
                //increment the count at index 2 for a range of 200 to 299
                count[2] += 1;
            if (income[i] >= 300 && income[i] <= 399)
            //increment the count at index 2 for a range of 200 to 299
                count[3] += 1;
            if (income[i] >= 400 && income[i] <= 499)
            //increment the count at index 2 for a range of 200 to 299
                count[4] += 1;
            if (income[i] >= 500 && income[i] <= 599)
            //increment the count at index 2 for a range of 200 to 299
                count[5] += 1;
            if (income[i] >= 600 && income[i] <= 699)
            //increment the count at index 2 for a range of 200 to 299
                count[6] += 1;
            if (income[i] >= 700 && income[i] <= 799)
            //increment the count at index 2 for a range of 200 to 299
                count[7] += 1;
            if (income[i] >= 800 && income[i] <= 899)
            //increment the count at index 2 for a range of 200 to 299
                count[8] += 1;
            if (income[i] >= 900 && income[i] <= 999)
            //increment the count at index 2 for a range of 200 to 299
                count[9] += 1;
            if (income[i] >= 1000)
            //increment the count at index 2 for a range of 200 to 299
                count[10] += 1;
            document.write("<br />");
            i++;
            //prompt for sales
            var string = prompt("Sales of Employee (Exit: 0):", "");
            var pay = parseInt(string);          
        }
        document.writeln("<h4>Range of salaries:</h4>");

        document.writeln("$200-$299 : " + count[2]);
        document.write("<br />");
        document.writeln("$300-$399 : " + count[3]);
        document.write("<br />");
        document.writeln("$400-$499 : " + count[4]);
        document.write("<br />");
        document.writeln("$500-$599 : " + count[5]);
        document.write("<br />");
        document.writeln("$600-$699 : " + count[6]);
        document.write("<br />");
        document.writeln("$700-$799 : " + count[7]);
        document.write("<br />");
        document.writeln("$800-$899 : " + count[8]);
        document.write("<br />");
        document.writeln("$900-$999 : " + count[9]);
        document.write("<br />");
        document.writeln(" over$1000 : " + count[10]);
    }
// -->
</script>
</head>

<body>
<hr />
</body>
</html>