I can’t understand this, could someone please explain?
while(slaying) {
if(youHit) {
console.log(“You hit the dragon!”)
}
else {
console.log(“Sorry, Dragon defeted you”)
}
slaying = false;
}
This part: if(youHit). Shouldn’t it be - if(youHit => 1)? I mean, youHit value could be 0. Isn’t it necessary to precise the if outcome?
no, because 0
is considered false where as 1
is considered true:
if (0){
console.log("0 is true")
} else {
console.log("0 is false")
}
if (1){
console.log("1 is true")
} else {
console.log("1 is false")
}
in the the end, it matters if the condition evaluates to true or false, this doesn’t have to be comparison, it can also be checking if a value is true or false.
1 Like
Ohh, very simple. Much clearer now, thanks a lot!