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


#1

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.. ?


#2

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


#3

sure.

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; }

           else{
               youHit = Math.floor(Math.random() * 2); 
           }

   }else{

       console.log("ohhh, unfortunately the dragon defeated you");
   }
       slaying=false;

}