title: Changing the interval of SetInterval while it's running
body: <p>I have written a javascript function that uses setInterval to manipulate a string every tenth of a second for a certain number of iterations.</p>
  
  <pre><code>function timer() {
      var section = document.getElementById('txt').value;
      var len = section.length;
      var rands = new Array();
  
      for (i=0; i&lt;len; i++) {
          rands.push(Math.floor(Math.random()*len));
      };
  
      var counter = 0
      var interval = setInterval(function() {
          var letters = section.split('');
          for (j=0; j &lt; len; j++) {
              if (counter &lt; rands[j]) {
                  letters[j] = Math.floor(Math.random()*9);
              };
          };
          document.getElementById('txt').value = letters.join('');
          counter++
  
          if (counter &gt; rands.max()) {
              clearInterval(interval);
          }
      }, 100);
  };
  </code></pre>
  
  <p>Instead of having the interval set at a specific number, I would like to update it every time it runs, based on a counter.  So instead of:</p>
  
  <pre><code>var interval = setInterval(function() { ... }, 100);
  </code></pre>
  
  <p>It would be something like:</p>
  
  <pre><code>var interval = setInterval(function() { ... }, 10*counter);
  </code></pre>
  
  <p>Unfortunately, that did not work.  It seemed like "10*counter" equals 0.</p>
  
  <p>So, how can I adjust the interval every time the anonymous function runs?</p>