The Second IF Statement - Dragon Slaying


#1

Can someone spot what's wrong with my syntax? I double-checked brackets and semi-colons, but must have something misplaced somewhere ... ? Thank you for looking!


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

var slaying = true;
while (slaying) {
if (youHit) {
console.log ("Congratulations, you hit the dragon!");
totalDamage += damageThisRound;
if (totalDamage >= 4) {
console.log ("You slew the dragon!)";
slaying = false;
}
else
{
youHit = Math.floor(Math.random()*2);
}
}
else
{
console.log ("Bummer, the dragon defeated you.");
slaying = false;
}
}


#2

@jmadala the problem is on this line:

console.log ("You slew the dragon!)";

You have the parentheses before the quotation mark at the end, instead of after. If you switch those two, it will run.


#3

Thank you very much @freginold!!