title: How to add onclick functions in an array of buttons using a for loop properly?
body: <p>I'm making a kind of HTML calculator to test something I have in mind.
  I've used a for loop to create the buttons of the keypad. The display is a text field.
  Then I used a for loop to add the functions in the buttons:</p>
  
  <pre><code>for (var i = 0; i &lt; 10; i++)
  {
      buttons[i].onclick = function()
      {
          display.value += i;
      };
  }
  </code></pre>
  
  <p>What I was trying to do is to make, for example, buttons[0] add "0" to the value of the text field when clicked. Instead, clicking any button added "10" in the text field. Why? How can I make it right?</p>