title: Access global variables in setInterval()
body: <p>I have a function to generate some random-ish numbers and inside that function I make a call to setInterval() because I need those numbers to refresh every 2 seconds.  </p>
  
  <pre><code>function genSine(val1, val2) {
  
      var freq = 0.1; // angular frequency
  
      var coords = function(x, y) {
          var amplitude = Math.floor((Math.random()*10)+1);
          var phase = Math.floor((Math.random()*20)+1);
          return {
              x : Math.sin(freq * (val1 + phase) * amplitude) + Math.floor((Math.random()*100)+1),
              y : Math.sin(freq * (val2 + phase) * amplitude) + Math.floor((Math.random()*100)+1)
          };
      }
  
      setInterval(function() {
          current = coords(50, 50);
          console.log('Val 1: ' + current.x);
          console.log('Val 2: ' + current.y);
      }, 2000);
  }
  
  genSine(10, 20);
  </code></pre>
  
  <p>This is all well and good, the values update as expected but my goal is to have two global variables (let's call them val1/val2) update within that setInterval() function.  It appears I have a scoping issue because those variables are not accessible within the function and I can not access the 'current' variable from outside that function.  I know I am missing something here, what is it?</p>
  
  <p>Fiddle: <a href="http://jsfiddle.net/niczak/4uNen/1/" rel="nofollow">http://jsfiddle.net/niczak/4uNen/1/</a></p>