title: How can I iterate each time the user presses a button?
body: <p>I have the following number-guessing game. It's an assignment for a class I'm taking. Every time I run the code, the "You have" + i + "chances remaining..." statements returns i as 0. How can I make it so that every time the user presses the Confirm button, it goes through the loop once and i decreases by 1?
  I need to have a loop in the assignment and a reset button!</p>
  
  <pre><code>&lt;body&gt;
      &lt;!-- GAME INSTRUCTIONS --&gt;
      &lt;h1&gt;Number Guessing Game&lt;/h1&gt;
      &lt;p&gt;A random number between 1 and 100 has been generated. Can you guess it?&lt;/p&gt;
      &lt;!-- FORM (Includes button to confirm guess, input box, and output box) --&gt;
      &lt;form id="Input" name="Input"&gt;
          &lt;input name="guess" placeholder="Insert your guess" type="number"&gt;
          &lt;input name="requestInfo" onclick="getResults()" type="button" value="Confirm"&gt;
          &lt;p&gt;&lt;/p&gt;
          &lt;textarea cols="50" name="results" readonly="true" rows="8"&gt;&lt;/textarea&gt;
          &lt;p&gt;&lt;/p&gt;&lt;input name="newGame" onclick="resetGame()" type="button" value="Start New Game"&gt;
      &lt;/form&gt;&lt;!-- JAVASCRIPT START --&gt;
      &lt;script type="text/javascript"&gt;
  
  // Define variables
  var num = Math.floor(Math.random() * 100) + 1;
  var turns = 10;
  
  function checkNumber() {
      var guess = parseFloat(document.Input.guess.value);
      while (turns &gt; 0) {
              if (guess == num) {
                  turns = 0;
                  document.Input.results.value = "Congratulations, you won! The mystery number was " + num + ".";
              } else if (guess &lt; num) {
                  turns--;
                  document.Input.results.value = "Your guess was too low. Turns remaining: " + turns;
              } else if (guess &gt; num) {
                  turns--;
                  document.Input.results.value = "Your guess was too high. Turns remaining: " + turns;
              }
      }
  }
  
  function resetGame() {
      turns = 10;
      num = Math.floor(Math.random() * 100) + 1;
      document.Input.guess.value = "";
      document.Input.results.value = "";
  }
  
  function getResults() {
      checkNumber();
  }
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>