2/6 "You didn't set slaying to true"?


#1

What is wrong with this ?

It says I didn't set slaying to true but I clearly did.

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 {
  youHit = Math.floor(Math.random() * 2);
}

} else {
console.log("The dragon burninates you! You're toast.");
slaying = false;
}
}



#2

In the larger text portion, in the if statement, once you slay the dragon slaying should be equal to true.


#3

Thank you, I tried that but it is still saying I didnt set it to true


#4

For exercise 2/6 this is all the code you need.





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




#5

Thank you so much! That worked!


#6

Ha, thank you. Same issue.