The second "if" statement help!


Hi I am a beginner here , I am stuck on part 5 of the dragonslayer lesson, here is my code im not sure why its not working.

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;    

I have indented my code but its not formatting for some reason.


I have a sneaking suspicion it has something to do with your curly a few places possibly.


Like @gwishin said, the problem is with your curly brackets.

You don't have a curly bracket that ends that if statement.
Also, there's one unnecessary curly bracket at the end. One for the while loop, one for the larger if/else statement, and one that just seems to be there to screw up your code.