Why this won't work help please


#1

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 = 1){
        console.log("You hit the dragon");
        totaldamage += damageThisround;
        if ( totaldamage >= 4) {
            console.log("You slew the dragon");
        }
        else{
            youhit = Math.floor(Math.random()*2);
        };
    }
    else{
        console.log("The dragon defead you");
    }
    slaying = false;
};

#2

here you need to use youHit,youHit == 1 or youHit ===1. The problem is that youHit = 1 does not compare youHit to 1 but changes it's value to become one and the overall statement has therefor a value of 1. As you probably heard 1 is a synonym for true in many programming languages just like in js so this statement is always true no matter what the value of youHit originally was.

Is this your problem or do you get an error message or stuff like this? Please give some more information :smile: