Dragon Slayer the second if statement


#1

I don't see why my code won't go through

var slaying = false;
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");
totalDamage += damageThisRound;
if(totalDamage >= 4){
console.log("the player slew the dragon");
slaying = false;
}else {
youHit = Math.floor(Math.random() * 2);
}
}else{
console.log("the dragon defeated you");
slaying = false;
}
}


#2

you have too much in formation copy mine

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


#3

what sorry wrong code


#4

try this code this is the right one

var slaying = true
var youHit = Math.floor(Math.random(0) * 2)
var damageThisRound = 2
var totalDamage = 0
var slaying = true;
while(slaying) {
slaying = false;
}
while(slaying) {
if (youHit) {
console.log("You hit!");
} else {
console.log("You missed!");
}
slaying = false;
}
console.log("I won I defeated the dragon in your face people who said i could not do it so you can all just kiss the darkest part of my as")
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;
}
}