title: Random Number Guessing Game - Limit the Number of guesses
body: <p>I'm trying to make a program that generates a random number which the user guesses. It also limits the number of guesses the user can make (or is supposed to.)</p>
  
  <pre><code>     var highLimit = 5;
          var randNum = Math.floor((Math.random() * highLimit) + 1);
          var allowedGuesses = 2;
          var numGuesses = 0;
  
          function guessingGame() {
              if (numGuesses &lt;= allowedGuesses) {                    
  
                 do {
                      inputNum = document.numForm.number.value;
                      inputNum = parseInt(inputNum);
  
  
                      if (inputNum &lt; randNum &amp;&amp; inputNum &gt; 1) {
                          document.numForm.gameResults.value = "Sorry, your guess was too low.";
                          numGuesses++;
                      }
  
                      else if (inputNum &gt; randNum &amp;&amp; inputNum &lt; highLimit) {
                          document.numForm.gameResults.value = "Sorry, your guess was too high.";
                          numGuesses++;
                      }
                      else if (inputNum == randNum) {
                          document.numForm.gameResults.value = "Congratulations! You guessed correctly.";
                          numGuesses++;
                      }
  
                      else {
                          document.numForm.gameResults.value = "Your guess was out of the desired parameters. Please guess again.";
                          numGuesses--;
                      }
  
                  } while(numGuesses &lt; allowedGuesses &amp;&amp; inputNum != randNum);
  
              }
  
                  else {
                      document.numForm.gameResults.value = "Sorry, you have reached the allowed number of guesses, which is " + allowedGuesses + "." + " Click 'New Game' to try again.";
                  }
              return false;
          }
  
          numGuesses = 0;
          function newGame() {
                  randNum = Math.floor((Math.random() * highLimit) + 1);
                  guessingGame();
                  return false;
             }
  </code></pre>
  
  <p>And the HTML: </p>
  
  <pre><code> &lt;form name = "numForm"&gt;
          &lt;fieldset&gt;
              &lt;label for = "randNum"&gt;Enter a number between 1 and 5: &lt;/label&gt;
              &lt;input type = "text" name = "number" value = "" id = "randNum" size = "1" maxlength = "1" /&gt;
          &lt;/fieldset&gt;
          &lt;input class = "button" type = "button" name = "submit" onclick = "guessingGame()" value = "Submit Number"  /&gt;
  
          &lt;input class = "button" type = "reset" name = "newGame" onclick = "newGame()" value = "New Game" /&gt;
          &lt;fieldset&gt;
              &lt;textarea name = "gameResults"  onclick = "" readonly = "true" value = "" rows = "5" cols = "40" &gt;&lt;/textarea&gt;
          &lt;/fieldset&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Right now, the program is stuck in a infinite loop since highLimit is set at 5. But if I set it at ten, the program works. How can I fix it so it works at any value? I would also appreciate other suggestions for improvement. </p>
  
  <p>Thanks in advance!</p>