title: Calculating the average of an array after the user inputs another number into the array
body: <p>I have a score text field that a user must input between 0 and 100 to add to the array. After displaying the the results, the average of the numbers in the array should be calculated. However, whenever I input a number the average is completely off and really high. How do I fix this? (e.g. array[88, 98, 77, 88] and input the number 99, the average jumps to 7039)</p>
  
  <p>My code: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var scores = [88, 98, 77, 88];
  
  var addScore = function() {
    var scoreInput = $("score").value;
    if (scoreInput.length == 0 || scoreInput &gt; 100 || scoreInput &lt; 0 || isNaN(scoreInput)) {
      alert("You must enter a valid score.");
    } else {
      scores.push(scoreInput);
    }
  }
  
  var displayResults = function() {
    var highest = Math.max(...scores);
    var total = 0;
  
    for (var i = 0; i &lt; scores.length; i++) {
      total += scores[i];
    }
    var average = total / scores.length;
  
    var output = "&lt;h2&gt;Results &lt;/h2&gt;&lt;br&gt;Average Score = " + average + ;
    $("results").innerHTML = output;
  };</code></pre>
  </div>
  </div>
  </p>