youHit=Math.floor(Math.random()*2 in the second else statement


Why do you have to use youHit=Math.floor(Math.random()*2 in the second else statement?

What if is the same as the first result? Lets suppose in the first youHit is true and this another one is true again.. ?


Do you think you could post your code for our viewing pleasure? This will help us figure out what you're talking about.



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 ("congratulations!you hit the dragon!");
totalDamage+=totalDamage + damageThisRound;

       if (totalDamage >= 4) {
           console.log("you slew the dragon!");
           slaying = false; }

               youHit = Math.floor(Math.random() * 2); 


       console.log("ohhh, unfortunately the dragon defeated you");