Dragon Slayer! (6/6) The dragon never kills me


#1


Dragon Slayer! (6/6, Well Done!)


It sais that i have finished the course, but whenever i run the code, dragon never wins. Could you explain me why? When i replace the first "if" statement (youHit = true) to (youHit) it works, but what is the difference?
Thanks :slight_smile:


Replace this line with your 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've hit the dragon!");
        totalDamage += damageThisRound;
        if  (totalDamage >= 4) {
            console.log("You've slain the dragon!");
            slaying = false;
        }
        else {
            youHit = Math.floor(Math.random() *2)
        }
    }
    else{
        console.log("The dragon has defeated you!");
    slaying = false;
    }   
}


#2

what is actually the problem


#3

okay i get it now....

"youHit == true" and "youHit" works just fine because any variable defined is equals to true except it is later set to false


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.