The second 'if' statement


#1


https://www.codecademy.com/courses/javascript-beginner-en-mrTNH-6VIZ9/0/5?curriculum_id=506324b3a7dffd00020bf661#

"Oops, try again. Does your second 'if' statement check to see if totalDamage is greater than or equal to 4?"

It says that I didn't check to see if the totalDamge is greater than or equal to 5, but it's there.
HELP.


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 hit the dragon!");
        totalDamage += damageThisRound;
        if (totalDamge >= 4) {
            console.log ("You win!");
            slaying = false;
        }
        else {
            var youHit = Math.floor(Math.random() * 2);
        }
    }
    else {
        console.log ("The dragon defeated you.");
        slaying = false;
    }
}


#2

You have Damge instead of Damage *Spelling mistake

Also didn't define slaying, before while loop add:

var slaying = true;

#3

Oh... Oops. Thanks! I figured it might be something stupid, but I guess I missed it.

:slight_smile:


#4

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