Dragon Slayer syntax error


#1

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 the dragon and did " + damageThisRound + " damage!");
    totalDamage += damageThisRound;
      }
    if (totalDamage >= 4) {
      console.log("You did it! You slew the dragon!");
      slaying = false;
    } else {
    console.log("yer dead.");
    slaying = false;
  }
}

error is: Oops, try again. It looks like you didn't set slaying to true. Except I have "true" at the very top -- where else should I have a slaying true?


#2

@lodum

The problems come from here. You closed your first if statement too early making that there are two if statement (which is not possible). Your first if statement should be wrapping the next if statement.


#3

Thank you thank you!