title: Using arrays to record number of clicks on a button
body: <p>last night I was coding a little piece of JS code that records the number of mouse clicks on a keypad (akin to a mobile phone) and with each successive press a new value would be entered into a textbox. This is how I've got so far.</p>
  
  <p>The difficulty last night was that I set count as a global variable which was carried across meant if a user clicked on 1 and 2 they would get 1D in the text box when they should be getting 12:</p>
  
  <p><a href="http://jsfiddle.net/JNCCW/7/" rel="nofollow">http://jsfiddle.net/JNCCW/7/</a></p>
  
  <p>In my most recent code I've tried to create an array so initially we have:</p>
  
  <pre><code>[0,0,0,0]
  </code></pre>
  
  <p>And each time the user clicks a button then e.g 1 and then 2 - the array updates to:</p>
  
  <pre><code>[1,1,0,0]
  </code></pre>
  
  <p>The values at 1 in array 1,2 are then added to the text box.</p>
  
  <p>When the array element equals 4 then the array element resets to 0.</p>
  
  <p><a href="http://jsfiddle.net/JNCCW/9/" rel="nofollow">http://jsfiddle.net/JNCCW/9/</a></p>
  
  <p>I've been having difficulty achieving this and feel that the logic behind my coding is awkward. I would appreciate any help!</p>