title: Guess a number game, score counter giving incorrect result
body: <p>I am making a simple 1 - 10 guess the number game with Javascript.<br>
  It can be viewed here <a href="http://www.ysk.co.za/guessing/index.html" rel="nofollow">Guessing game</a> <br> <br>
  To add up score i have a <code>var score = 4</code> which de-increments each time the number guessed (with a <code>for</code> loop which is smaller than 5) incorrect. I <code>+=</code> to <code>var tally</code> and display <code>tally</code> as score. <br>
  My problem is <code>score</code> always equals 0, and therefore does not add anything to tally, I am struggling to find a solution. <br>
  My javascript is:</p>
  
  <pre><code>var tally;
  function play() {
  
      var compNum = (Math.random() * 10).toFixed(0);
      var score = 4;
      for (var i = 0; i &lt; 4; i++) {
  
          if (i == 0) {
              var userNum = prompt("Enter a number between 1 and 10");
          } else {
              if (userNum &lt; compNum) {
                  userNum = prompt("Guess higher, you have " + (4 - i) + " turns left ", userNum);
              } else if (userNum &gt; compNum) {
                  userNum = prompt("Guess lower you have " + (4 - i) + " turns left ", userNum);
              }
          }
          score--;
  
      }
  
      tally += score;
      $("#score").html("score: " + tally);
  
  
      if (i &gt;= 3 &amp;&amp; userNum != compNum) {
          var again = confirm("Sorry you lost. The number was: " + compNum + " Play again?");
      } else if (userNum == compNum) {
          again = confirm("Well done! play again?");
          i &lt;= 5;
      }
      if (again) {
          play();
      }
      if (userNum == "") {
          i &lt;= 5;
      }
  
  
  }
  </code></pre>
  
  <p>HTML: </p>
  
  <pre><code>&lt;button onclick="play()"&gt;PLAY&lt;/button&gt;
  &lt;div id="score"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Your help is really appreciated</p>