title: Getting the average returns NAN - JS
body: <p>I am writing a function called "computeAverageOfNumbers".</p>
  
  <p>Given an array of numbers, "computeAverageOfNumbers" returns their average. </p>
  
  <p>Notes:<br/></p>
  
  <ul>
  <li>If given an empty array, it should return 0.</li>
  </ul>
  
  <p>Here's 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>function computeAverageOfNumbers(nums) {
    var total = 0;
    for (var i = 0; i &lt; nums.length; i++) {
      total += nums[i];
    }
    var avg = total / nums.length;
    return avg;
  }
  
  var input = [];
  var output = computeAverageOfNumbers(input);
  console.log(output); // --&gt; returns NaN instead of 0</code></pre>
  </div>
  </div>
  </p>
  
  <p>As you can see my code returns NaN when you submit an empty array but works if you put regular array items like <code>var input = [1,2,3,4,5];</code></p>
  
  <p>If given an empty array, it should return 0.</p>
  
  <p>Am I missing something?</p>