? Unexpected keyword 'else' HELP! 5/6


#1

*Can anyone figure out why I'm being told that 'else' is an "unexpected keyword?"
This is my 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 hit the dragon! Nice one!");
        totalDamage += damageThisRound;
        if (totalDamage >= 4) {
            console.log("Wow! Amazing! The dragon is slain.");
            slaying = false;
        else {
            youHit = Math.floor(Math.random() * 2);
            }
    } else {
        console.log("Ouch! The dragon incinerated you.");
    slaying = false;
    }
}

#2

haxor has the right solution, i withdraw my answer


#3

Well, I see what you mean. But I passed the section only by copying the code at the beginning. Now I know what was wrong though, so I guess it's okay.


#4

The two elses are ok as they are on two different levels of nesting but here:

if (totalDamage >= 4) {
            console.log("Wow! Amazing! The dragon is slain.");
            slaying = false;
        else {

the if lacks a closing } so the else comes unexpected.


#5

Thanks! I didn't see that at all...