Error message "SyntaxError: Unexpected token else" keeps showing up


#1

The error message "SyntaxError: Unexpected token else" keeps showing up, but as far as I can tell, my code is correct. If anyone can tell me what's wrong, I would be very grateful!

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!");
        totalDamage += damageThisRound
        if(totalDamage >= 4) {
            console.log("You win!");
            slaying = false
        } else {
            youHit = Math.floor(Math.random() * 2);
    } else {
        console.log("You lose!");
    }
slaying = false;
}

#2

Nevermind, I figured it out!


#3

Guess it was a missing } here:

} else {
            youHit = Math.floor(Math.random() * 2);
} // missing

as because of this 2 else came following each other.
General hint if you answer a question yourself please either provide information that are useful for later readers with the same question or just delete it, thank you.