Why?! Why?! Why can't I stop the word 'false' coming up! Please help!


#1

Please help! I can;t stop the word false coming up in the box on the right! Whenever I try to fix it, I end up with an infinite loop or it stays the same.

Replace this line with your code.

`


#2

The interpreter sees the last value that you assigned,

slaying = false;

And displays it in the window.

A good way I found to remove this is to add:

console.log(" ");

To the end of your code. :slight_smile:


#3

Thank you so much! I added it to both 'slaying = false;' and it did the job! :slight_smile:


#4

You could also just swap the slaying = false with your existing console.log. As @cadecodes already explained the last value in your code is always echoed to the console with an exception for undefined and the "value" of console.log is undefined. So as the console.log doesn't depend on the slaying = false you can swap them and thereby get rid of the false. But as said it is just an echo of the last value and not harmful in any way.


#5

Brilliant! Thank you very much :slight_smile:


#6

Hi @haxor789 and @cadecodes ,

I'm confused by what you mean by "swap them"? Swap the last slaying = false to console.log("slaying=false")? Why does making it a string help? Isn't it still in the while function?

Any additional explanation would be greatly appreciated :slight_smile:


#7

By swapping I just meant that you should change the places e.g.

console.log("Something about winning or loosing ...");
slaying = false;

to:

slaying = false;
console.log("Something about winning or loosing ...");

As these two statements do not depend on each other this doesn't change anything in your code but the expression slaying = false has a value of false, which is displayed if it is the last statement in the code and console.log(...) has no such value (undefined) which is not displayed. So changing the order of those two statements gets rid of the false in the console.


#8

I did not know. How interesting! Thank you so much @haxor789!