Find the sum of a Javascript array and divide by its length
<p>I'm almost embarrassed to ask this.</p>

<p>I'm a beginner programmer, and Javascript is very confusing to me. I managed to put together this much with the help of my instructor, but there are some simple things I can't get right.</p>

<p>I tried search Stack Overflow for a thread that would answer my question, but all of them I've seen contain code that I haven't learned about yet, so they're all just gibberish to me.</p>

<p>What I'm trying to do is add all the values of an Array and divide the sum by the array's length, ergo, find the average. The description of the assignment is find the average of any number of students' grades.</p>

<p>My two problems are </p>

<ol>
<li>I can't figure out how to get the sum of all numeric values in the Array and,</li>
<li>For some reason, array.length returns one more than the actual length of the Array, even if I add a -1. (ex. if I enter 6 values, the array.length would return 7.)</li>
</ol>

<p>I know where the problem is but I can't figure out what I need to enter. This assignment is due tomorrow, so anyone's time and effort is appreciated.</p>

<p>Here is my script:</p>

<pre><code>&lt;script type="text/javascript"&gt;
    var allGrades = new Array();
    var g = 0;
    var l = 0;
    var s = 0;
    var t = 0;
    do {
        allGrades[g] = window.prompt("Please enter one grade for each window. After you enter a grade, enter an 'x' to see the average of the grades you entered.", "")
        g++;
    }
     while (allGrades[g - 1] != "x")
     for (l = 0; l &lt; allGrades.length - 1; l++) {
        s += allGrades[l] // Where I think the problem is
    }
    t == s / g - 1;
    g == allGrades.length - 1; //
    window.alert(g)
     switch (t) {
        case (t &gt;= 90):
            window.alert("Your average grade is " + (t) + ". " + "This is an A.")
            break;
        case (t &gt;= 80 &amp;&amp; t &lt; 90):
            window.alert("Your average grade is " + (t) + ". " + "This is a B.")
            break;
        case (t &gt;= 70 &amp;&amp; t &lt; 80):
            window.alert("Your average grade is " + (t) + ". " + "This is a C.")
            break;
        case (t &gt;= 60 &amp;&amp; t &lt; 70):
            window.alert("Your average grade is " + (t) + ". " + "This is a D.")
            break;
        case (t &lt;= 60):
            window.alert("Your average grade is " + (t) + ". " + "This is a failing grade.")
            break;
    }
&lt;/script&gt;
</code></pre>

<p>I'm sorry if what I'm asking seems dumb. I've only been taking web programming for about two months, so I could really use some help!</p>

<p>Kyle</p>
