Don't understand second 'else'


#1

Why we must write
else {
youHit = Math.floor(Math.random() * 2);}
What it mean?


#2

Please show your complete Code


#3

var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var damageRound = Math.floor(Math.random()*5 + 1);
var totalDamage = 0;
while (slaying){
if(youHit){
console.log("You hit the dragon ")
totalDamage += damageRound;
if(totalDamage >= 4){
console.log("You are win!")
slaying = false;}
else {
youHit = Math.floor(Math.random() * 2);}
}else
{console.log("You missed")
slaying = false;
}

}

#4

Your console will run else if your "if" is false or not true. For example:

if(1 === 0) {
console.log("This is not correct")
}
else {
console.log("This is correct")
}

In this example i said if 1 is equal to 0 then say "This is not correct" (you can put whatever you want between the parameters) but this is not correct because 1 is not equal to 0 or 2 or 3 and so on because 1 is 1 so it will run the else statement because 1 is not equal to 0. I hope you understand it now