Its says correct but it wont console.log my phrase


#1

x = true;

var x = function(number){

while(x<10){ 

    console.log("While LOOPING!!!!!");

    x=false;

            }     };

x(0);

could someone explain it please ?


#3

ok i did one loop where it console.log my phrase, then i tried this one:

var x = 0;

while(isNaN(x)){ 

    console.log("W!");

    x="Hi";

    x=2;

    x="Hey";

            }

and i get correct but it won't console.log my phrase ??


#4

Why do you combine all sorts of datatypes without reasonable connection?

in your question x is first a boolean (true), btw not declare (forgot the var). Then it becomes a function which is called by a value of 0. Inside the function x is used in the condition of the while loop as if it would be a number and last but not least it is overwritten by false.

I'll hint if you want variables to have different tasks then you can name them differently. This might even increase your own overview about what is actually happening. Also in javaScript types not seem to be that strict so "42" for example has a value of 42 and true and false have a value of 1 and 0 and vice versa but as this is not covered in this track and not that useful for beginners either it is better if you stick to reasonable conditions. So when you have x < 10 as condition you should make sure that x is a number and not a boolean. Here with x = false this would means 0 < 10 which is true and therefore you have an infinite loop so be careful and use types that you can evaluate by yourself without googling what the result actually is.

The second one has a similar problem. Why do you confuse yourself with this?

 x="Hi";

    x=2;

    x="Hey";

x being a string a number and a string again. Also in this series only the last statement makes the value so x="Hi"; and x=2; are pretty pointless, aren't they? Anyway as you start with 0 and 0 is a number your isNaN(x) tells you "false, 0 is a number" and therefore the loop will not even start.

So again maybe just keep it simple until you really understand what you're doing and then you can go crazy again :smile: