Does it matter?


#1

My code is allowed to pass the waypoint:

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

Your recommendation is to input like this:

while(slaying) {
    if (youHit) {
        console.log("You hit!");
    } else {
        console.log("You missed!");
    }
    slaying = false;
}

The question is in topic and also, what's the differences between input this line slaying = false; at the end or at the beggining?


#2

Well slaying is the condition of your while loop so setting slaying from true to false will stop the while loop from running. Here the slaying=false is executed in both ways so there isn't a difference whether you do it sooner or later if it is done anyway.