title: Global vars with jsFiddle
body: <p>In the jsFiddle environment, I wish to create a loop that displays numbers 1 thru 10 in random order, with no repeats.</p>
  
  <p><a href="http://jsfiddle.net/mCFGf/" rel="nofollow noreferrer">jsFiddle here</a></p>
  
  <p>Among other things, having difficulty with global variables in the jsFiddle environment.</p>
  
  <p>Would appreciate:</p>
  
  <ol>
  <li>Explanation re global vars in jsFiddle</li>
  <li>Making my code work (desired goal: print numbers 1 to 10 in random order, via loop)</li>
  </ol>
  
  <p>Thank you</p>
  
  <p>For posterity, here is the code from the jsFiddle:</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;div id="response"&gt;&lt;/div&gt;
  &lt;input type="button" id="mybutt" value="Get Next" /&gt;
  </code></pre>
  
  <p><strong>javascript/jQuery:</strong></p>
  
  <pre><code>var cnt;
  var window.arrDone = [];
  
  function nextQues() {
      return Math.floor(Math.random()*3) + 2;
  }
  
  $('#mybutt').click(function() {
      cnt++;
      console.log('Count is now: ' + cnt);
      if (cnt &lt; 10) {
          nn = nextQues();
          console.log('Testing: ' + nn);
          if (window.arrDone.indexOf(nn) &gt; -1) {
              console.log('Already Seen: ' + nn);
          }else{
              console.log('FOUND NEW: ' + nn);
              window.arrDone.push(nn);
          }
          $('#mybutt').trigger('click');
      }
  });
  </code></pre>
  
  <hr>
  
  <p><strong>For Posterity:</strong></p>
  
  <p>Anyone stumbling across this question while researching their own solution should also check out this, related, SO post:</p>
  
  <p><a href="https://stackoverflow.com/questions/18855434/is-javascript-namespace-polluted">Is javascript namespace polluted?</a></p>
  
  <ul>
  <li>Ensure you read the answer by Joe Enos, and comment discussion underneath</li>
  </ul>