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


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)
        console.log("The dragon has defeated you!");
    slaying = false;


what is actually the problem


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


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