title: JavaScript setInterval loop not holding variable
body: <p>Here is my code:</p>
  
  <pre><code>    var showNo = 1;     
      window.setInterval(function() {
            console.log(showNo);
            if(showNo === 1) { var nextNo = 2;  }
            else if(showNo === 2) { var nextNo = 3;  }
            else if(showNo === 3) { var nextNo = 4;  }
            else if(showNo === 4) { var nextNo = 5;  }
            else if(showNo === 5) { var nextNo = 1;  }
            else { var showNo = 1; var nextNo = 2; }
  
            var showNo = nextNo;
            }, 500);
  </code></pre>
  
  <p>My question is, why is the showNo variable not holding when the setInterval loop starts? The console displays 'undefined' in the above example. This may be a simple question, but I am trying to teach myself query and this has me stuck.. </p>
  
  <p>Any answers would be great. </p>
  
  <p>Thanks. </p>