title: JS for loop not working correctly, trying to loop through an array of variables
body: <p>I am trying to code the dice game Yahtzee in Javascript for fun.  I have a basic interface set up with images of dice.  In reference to my problem, a few Yahtzee rules to know would be:</p>
  
  <p>There are 5 dice</p>
  
  <p>After 3 rolls, the player has to pick a points category to score with</p>
  
  <p>Here is the code that is not working:</p>
  
  <pre><code>var die1 = Math.floor((Math.random() * 6) + 1),
  die2 = Math.floor((Math.random() * 6) + 1),
  die3 = Math.floor((Math.random() * 6) + 1),
  die4 = Math.floor((Math.random() * 6) + 1),
  die5 = Math.floor((Math.random() * 6) + 1),
  dieArray = ["", die1, die2, die3, die4, die5],
  optionResult1 = 0;
  
  document.getElementById("option1").onclick =  function() {
  if (rollCount == 3 &amp; option1 == false) {
      for (i=0; i &lt; 5; i++) {
          i++;
          if (dieArray[i] == 1) {
              optionResult1++;
          }
          if (i = 5) {
              option1 = true;
              document.getElementById("optionResult1").innerHTML = optionResult1;
              console.log("finished");
          }
      }
              console.log(optionResult1);
  } else if (rollCount != 3) {
      document.getElementById("dialogue").innerHTML = "You cannot pick this yet because you have not rolled 3 times.";
  } else if (option1 == true) {
      document.getElementById("dialogue").innerHTML = "You cannot pick this because you have already used this category.";
  }
  }
  </code></pre>
  
  <p>What should happen (assuming it's the third roll and this points category has not already been chosen previously):</p>
  
  <p>The for loop should go through the dieArray and for each die that is a "one", add 1 to the optionResult1 variable.  If there were three "ones" out of five dice, optionResult1 should be "3", etc.</p>
  
  <p>What instead happens is that it usually comes back as 1 less than what it should be.  Even if I can see in the console that the array clearly shows three "ones", it will give me "2", or sometimes "0".  Is there anything wrong with the code you see?  There is obviously other code in the document, but I am fairly certain the problem is within this function.  Sorry if this was confusing, it's probably easier to understand if you have played Yahtzee...</p>
  
  <p>I know that I could do the same thing with 5 if statements instead, but I am trying to learn from this and I am fairly confident this SHOULD work, I must just be doing something wrong.  Thanks!</p>