I keep getting the error.. Oops you didn't set


#1

I keep getting the error ... you didn't set slayer to true. Yet it is set to true very first statement

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


while (slaying) {
    console.log(youHit);
  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 {
      youHit = Math.floor(Math.random() * 2);
      console.log("made it here" + totalDamage);
      slaying = true;
    }
  } else {
    console.log("The dragon burninates you! You're toast.");
    slaying = false;
  }
}

#2

slayer, not slaying? maybe changing the variable name will fix it?


#3

var slaying = true ;
var youHit = Math.floor(Math.random() * 2);
var totalDamage=0;
var damageThisRound= Math.floor(Math.random()* 5 + 1);
while(slaying){
if(youHit){
console.log("You hit the dragon.!!!");
totalDamage +=damageThisRound;
if(totalDamage>=4){
console.log(" Ya hoo!!you killed the dragon!");
slaying=false;
}else{
youHit =Math.floor(Math.random() * 2);
}

    }else{
        console.log("The dragon defeated you !");
        }

slaying = false;
}

this my code ...