How to count to 3?
<blockquote>
  <p><strong>Possible Duplicates:</strong><br>
  <a href="http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example">Javascript closure inside loops - simple practical example</a><br>
  <a href="http://stackoverflow.com/questions/3953746/javascript-closure-stores-value-at-the-wrong-time">Javascript closure &ldquo;stores&rdquo; value at the wrong time</a>  </p>
</blockquote>



<pre><code>for (var i = 1; i &lt;= 3; ++i) {
    setTimeout(function() {
        alert(i);
    }, i * 1000);
}
</code></pre>

<p>This alerts "4" 3 times. I know why, but I won't spoil it here... although I forgot how to fix it. What's a concise way of solving this problem?</p>
