title: how to reset variable in javascript
body: <p>this is the code</p>
  
  <pre><code>var x = Math.floor( Math.random() * 10 );
  setInterval(function () {
  
      if (x &gt;= 5) {
            $('.test').show();
            setTimeout(function () {
                           $('.test').hide();
                   }, 2000);
      } else {
          x = Math.floor( Math.random() * 10 );
      }
  
  }, x * 1000);
  </code></pre>
  
  <p>this code show <code>.test</code> with the same random like if the <code>x=8</code> it will stay 8 and doesn't change what I really want is changing <code>x</code> to another number</p>
  
  <p>I've tried to put <code>var x</code> in the local scope and it show me <code>x</code> in <code>setInterval</code> is undifined</p>
  
  <p>I wanna <code>$('.test')</code> shows in a random way between 5 and 10 second like first time shows after 7S and second time shows after 9 second, etc... .</p>