The console logged SyntaxError: Unexpected token else what's wrong with this?


#1


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


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 ("Awesome! You hit!");
        totalDamage += damageThisRound;
        if (totalDamage >= 4) {
            console.log ("Great! You win!");
            slaying = false
        } else {
            youHit = Math.floor(Math.random() * 2);
        }
    } else {
        console.log ("Well too bad, We'll give him a good funeral.");
        slaying = false
    } else {
        console.log ("Crap, You missed.");
    }
    slaying = false;
}


#2

else is an optional second part of an if-statement, so your error message is that you have an else in a situation other than that.


#3

I just counted and I have 3 else parts and 2 ifs maybe that's the problem?


#4

I just removed the last one and past it. lol It looked harder


#5

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