title: Pushing array generated inside a function to a global variable
body: <p>Can someone help me understand why I can't push an array to the generatedNumbers global variable with this function:</p>
  
  <pre><code>var totalFrames = document.getElementById("totalFrames").value;
  var framesToSkip = document.getElementById("framesToSkip").value;
  var generatedNumbers = [];
  
  function clickGenerate() {
    for (var i = 1; i &lt;= totalFrames; i++) {
      if ((i % framesToSkip) === 0) {
        // do nothing
      } else {
        generatedNumbers.push(i);
      }
    }
    document.getElementById("numberList").innerHTML = generatedNumbers;
  }
  </code></pre>
  
  <p>You can see it accompanied by the html here:</p>
  
  <p><a href="https://jsfiddle.net/bdorrance/wszzvpu1/" rel="nofollow">https://jsfiddle.net/bdorrance/wszzvpu1/</a></p>
  
  <p>If I put the variables inside the function, it works fine, but I need the variables to be global so they can be accessed by other functions. You can see that code here:</p>
  
  <p><a href="https://jsfiddle.net/bdorrance/t246rnxe/" rel="nofollow">https://jsfiddle.net/bdorrance/t246rnxe/</a></p>