title: Javascript: Math.random() variable changes each time the variable is referenced?
body: <pre><code>var slaying = true;
  var youHit = Math.floor(Math.random() * 2);
  var damageThisRound = Math.floor(Math.random() * 5 + 1);
  var totalDamage = 0;
  
  while(slaying){
      if(youHit){
          console.log("You slice the dragon!")
          totalDamage += damageThisRound;
          if(totalDamage&gt;=4){
              console.log("Dragon is deafeated!");
              slaying=false;
          }
          var youHit = Math.floor(Math.random() * 2);
      }else{
          console.log("Dragon is too strong for you. Defeated.")
          slaying=false;
      }
  }
  </code></pre>
  
  <p>This is a short program on a tutorial for Javascript. However, I don't see how damageThisRound would ever change value. </p>
  
  <p>It is initialised at the top with the Math methods. Then we start the game in the While loop, where the value of damageThisRound never changes. Obviously it should change each time we loop (for each 'round' or 'hit') but nothing changes it within the loop. Am I missing something here?</p>