Lesson 5, expected expression, got keyword 'else'


#1

HI all, could you please help me, why it is wrong? I can't find my mistake...

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

var slaying = true;
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 misses!");
slaying = false;
}
}


#2

Check this line.

totalDamage += damageThisRound; {

#3

thanks a lot, it works :smile: