Extra False While slaying the dragon


#1

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!");

    totalDamage += damageThisRound;

    if ( totalDamage >= 4) {
        console.log("You have slayen the dragon!");    
        slaying = false;
    } else {
        youHIt = Math.floor(Math.random() * 2);
    }

} else {
    console.log("The dragon defeated you.");
}


slaying = false;

}
My code adds an extra "false" after execution.


#3

The console has a feature that echoes the last value in your code (unless it is undefined). So this is not really a problem. What is a problem is that slaying=false comes after your else and not inside of it because now the loop will always stop after the first loop.