Lesson 5 syntax error?


#1

this is my code:

var slaying = true
youHit = Math.floor(Math.random()*2);
damageThisRound = Math.floor(Math.random()*5 + 1)
totalDamage = 0

while(slaying) {
slaying = false;
}
if (youHit == 1) {
console.log("you hit the dragon!");
totalDamage += damageThisRound;
if (totalDamage >= 4) {
console.log("you slayed the dragon!")
slaying = false;
}
else {
youHit = Math.floor(Math.random()*2);

}
else{
console.log("the dragon defeat you!");
slaying = false;
};

I can't find what's wrong with the syntax. Can anyone help me?

error: SyntaxError: Unexpected token else


#2

You need to close your first if

else {
            youHit = Math.floor(Math.random()*2);
//here you miss a }
}
else{
    console.log("the dragon defeat you!");

#3

oh thank you :wink: didn't see that