title: JavaScript average function
body: <p>I am currently in a web programming class that is taught by a business professor. Naturally he doesn't know much about code and just points me to the book (which is a giant mess of spaghetti everywhere). </p>
  
  <p>The exact assignment I am having issues with is here in in quotes. Hopefully this doesn't look too messy.</p>
  
  <p><strong>DATA AVAILABLE</strong></p>
  
  <blockquote>
    <p>There is a local storage value you will need named: qualifier<br>
      There is a local storage value you will need named: factor<br>
      There is an array you will need named: sales<br>
      The array and local storage exist so just use them.  </p>
  </blockquote>
  
  <p><strong>WHAT TO RETURN</strong></p>
  
  <blockquote>
    <p>Return the average bonus. </p>
  </blockquote>
  
  <p><strong>HOW TO CALCULATE AVERAGE BONUS</strong></p>
  
  <blockquote>
    <ol>
    <li>Each amount in the array sales[] that is more than qualifier gets a bonus.<br>
    <strong>Remember</strong>: array means you think for() loop.</li>
    <li>The bonus is calculated as that sales amount times factor.</li>
    <li>If the sale is greater than qualifier add the bonus to the bonus total.</li>
    <li>Calculate the average by dividing the total by the number of bonuses that qualify.<br>
    <strong>Remember</strong>: you are returning the average of bonuses that qualify; not the total of bonuses. </li>
    </ol>
  </blockquote>
  
  <p>I understand that this site is not for you folks to simply do my homework for me, I do not expect that to happen. Below is the current code of what I have. I should note that the teacher has us submit our code into a console that is developed by the university. The reason I say this is because in this assignment, certain local storage variables are already defined, as well as the array. I have been trying to test this function out using notepad and saving it in an HTML document and testing it with a browser. You will notice that my code below is written to be tested with a browser, and that I have defined the array and localstorage variables myself. Hope that makes sense.</p>
  
  <p><strong>Here is my JavaScript</strong>: </p>
  
  <pre class="lang-js prettyprint-override"><code>sales = new [Array]();
  
  sales[0] = 3;
  sales[1] = 167;
  sales[2] = 191;
  sales[3] = 1;
  sales[4] = 45;
  
  localStorage.qualifier=5;
  localStorage.factor=2;
  
  total = 0;
  
  function myFunction() {
       for (i=0;i&lt;sales.length;i++){
            if (sales[i]&gt;localStorage.qualifier) {
                 bonus = sales[i]*localStorage.factor;
                 total = total + bonus;                 
            };
            avg = total/bonus;
       };
       return avg;
  };
  myFunction();
  
  alert(extraPay())
  </code></pre>
  
  <p>I want to write the function to calculate the average bonus. I tried using this web-based text editor from repl.it, and am getting a type error saying the object is not a function. I googled the error, which led me to this site and subsequently creating an account. Thank you so much for your time, if you could point out where my code goes wrong, or if I am just crazy all over the place, that would really help. Thanks! Sorry for the excruciatingly long post.</p>