Make your own free website on Tripod.com
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>
  
  <head>
    <title>
      Sales Frequencies
    </title>
    <meta name="GENERATOR" content="Arachnophilia 4.0">
    <meta name="FORMATTER" content="Arachnophilia 4.0">
<script language="JavaScript">
<!-- ;

  var frequency = new Array( 0,0,0,0,0,0,0,0,0 );

   function print() {
    var range;

      document.writeln( "<TABLE BORDER = '1' ALIGN='center' CELLPADDING='4'>" );
    document.writeln("<CAPTION><h3>WEEKLY SALES</h3></CAPTION>");
      document.writeln( "<TR><TD><B>Salary Range</B>" +
                        "<TD><B>Earned by</B></TR>" );

      for ( var i = 0; i < frequency.length;  i++ ) {
      range = "$" + (i*100+200);
      if( i == 8)
        range = range +" and over";
      else
        range = range + "-$" + (i*100+299);
         document.writeln( "<TR><TD>" + range +
                           "</TD><TD ALIGN='center'>" + frequency[ i ] + "</TD></TR>" );
      }

      document.writeln( "</TABLE>" );
   }

  function addSales() {
    var gross = parseInt( document.forms[ "gross" ].sales.value );
    var salary = 200 + ( gross * .09 );
    if( salary < 300 )
      ++frequency[0];
    else if ( salary < 400 )
      ++frequency[1];
    else if ( salary < 500 )
      ++frequency[2];
    else if ( salary < 600 )
      ++frequency[3];
    else if ( salary < 700 )
      ++frequency[4];
    else if ( salary < 800 )
      ++frequency[5];
    else if ( salary < 900 )
      ++frequency[6];
    else if ( salary < 1000 )
      ++frequency[7];
    else
      ++frequency[8];

    document.forms["gross"].sales.value="0";
    document.forms["gross"].sales.select();
    document.forms["gross"].sales.focus();

  } // function addSales()

// end hide -->
</script>
  </head>
  
  <body>
    Exercise 12.10    <i>(Don't use Netscape)</i>
    <p>
    
    <form name="gross">
      
      <table align="center">
        <tr>
          <td>
            Enter a salesperson's gross sales for the week
            <br>
            <input type="text" name="sales" size="20" maxlength="20" value="0">
            <br>
            <input type="button" name="enter" value="Enter" onclick="addSales()">
            <input type="button" name="done" value="Done" onclick="print()">
          </td>
        </tr>
      </table>

    </form>
    
    <p>
    
    View Source
  </body>
  
</html>