Why does it always end in false?



How do I stop it from printing false at the end? It runs through the loop until the condition is false, just as it should, but then it prints 'false,' which it shouldn't. It's a useless piece of information that is immersion breaking if you're building a game, and just plain bad in any other case. For example, the following will print something about you either damaging the dragon or dying until either you win or die. Then it prints false.

while (slaying) {
  if (youHit) {
    console.log("You hit the dragon and did " + damageThisRound + " damage!");
    totalDamage += damageThisRound;
    if (totalDamage >= 4) {
      console.log("You did it! You slew the dragon!");
      slaying = false;
    } else {
      youHit = Math.floor(Math.random() * 2);
  } else {
    console.log("The dragon burninates you! You're toast.");
    slaying = false;


this problem is caused by the console, because you update a variable after the last console.log()

you could simply print an empty string at the end, to ensure false isn't printed

its nothing to worry about, the console has been echoing the last update variable throughout the course, its nothing new


Why does it do that? Is that a problem with codecademy or JS in general?


some consoles have this behavior (including codecademy). Its not that relevant even, consoles are generally only used for debugging. Output is often displayed html webpages.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.