Why does 'false' show up on the console every time I run this program?


#1




https://www.codecademy.com/courses/javascript-beginner-en-mrTNH-6VIZ9/0/6?curriculum_id=506324b3a7dffd00020bf661


Whenever I hit save&submit code, 'false' is displayed on the console. The program works fine, but console.log("false") isn't written anywhere in my code. Why is it showing up and how do I hide it?


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 === 1) {
        console.log("You shoot the dragon with a pistol.")
        totalDamage = totalDamage += damageThisRound;
        if (totalDamage >= 4) {
            console.log("You pwned that dragon n00b.")
        }
        else {
            youHit
        }
    }
    else {
        console.log("Get rekt")
    };
    slaying = false
};


#2

This is normal behaviour for Javascript; the last defined value of a function or statement (if nothing is returned) is printed to the console for debugging purposes.

In this case, it's where you have defined slaying = false.