Step 3


#1

My instructions are:
Create a while loop that only executes when slaying is true. For this exercise, set slaying to false in the body of the loop. (We want to make sure the loop can exit—no infinite loops for us!)

I understand the need to make sure the loop can exit. My question is, when creating the condition to be false in the loop, when you run it, in the console, it not only prints "You did damage!" but under it it prints out "false". In Codecademy's code of the Dragon Slayer, "false" also prints out in the console, but in other projects, making the condition false doesn't print out "false" in the console. Also I wouldn't think it is wanted to have it print out in the console as there is no purpose for 'false' to print for the player of the game. "false" continues to print in the console through the entire game.

var slaying = true;
var youHit = Math.floor(Math.random()*2);
var damageThisRound = Math.floor(Math.random()*5 + 1);
var totalDamage = 0;

while(slaying) {
console.log("You did damage!")
slaying = false;
}


#2

Are you not able to pass this lesson, or is this just a question?


#3

I believe the "false" that appears on your screen is normal. Might be something Codecademy does for a reason. Not sure what, though. I receive "false" too, so I don't think you did anything wrong, if that's what you're asking.


#4

I'm able to pass the lesson, its just a question. It seems odd in the console for 'false' to keep printing when it doesn't have a purpose for the player of the game. No reason is given or even noted that false will print in console for 'x' reason. Was curious as to the why its there. Thank you.


#5

I believe I read in one of the lessons that they are just testing something by printing that. It may be fixed, or worked around in the future, but I think they have it there for a reason for now. Hope I was able to help :smiley:


#6

Thank you! I missed that blurb. Suppose I was focusing more on the lesson itself :smiley: Makes sense though as I've noticed some lines like that print in the console and other lessons, the line similar doesn't print in console. Good to know!


#7

No problem! Glad I could help! :smiley: