title: How can I use setInterval or setTimeout and display the results during the count?
body: <p>I'm trying to make a timer count down from 5 seconds to zero before a function is called, and I can do that successfully, but I haven't yet been able to display the timer value as it counts down. Instead of displaying the values, the <code>&lt;div&gt;&lt;/div&gt;</code> goes from a blank space to "Number: 0".  I've used both <code>setTimeout</code> and <code>setInterval</code> with the same result.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      for (i = 5; i &gt; 0; i--) {
          function countDown() {
              setInterval(function () {
                  document.getElementById("displayDiv").innerHTML = "Number: " + i;
              }, 1000);
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p><em>I also tried using <code>.value</code> in place of <code>.innerHTML</code> with no help.</em></p>
  
  <pre><code>&lt;input type="button" value="Count" onclick="countDown()" /&gt;
  
  &lt;div id="displayDiv" /&gt;
  </code></pre>
  
  <p>This seems like it should be really simple, but it has me stumped.  Any help is appreciated</p>