Question 6/11 "Solo flight"


#1

Hello, can someone please check my code and see what is wrong.
//Remember to make your condition true outside the loop!

var soloLoop = function(){
var soloLoop = true;
while(soloLoop) {
console.log("Looped once!");
soloLoop = false;
};

soloLoop();

If you figure out the problem, could you please tell me, in depth, what I need to do so that I may realise my mistake.


#2

Think about soloLoop, once you assigned it a function, but inside you assigned it true. What happens when you call it? You can't call true.


#3

cadecodes is correct, but aside from that, I tried your code and it was very close to working. (In fact, it works with one added character.)

The "while" loop was not closed properly, so the code didn't understand where to end that loop. After setting soloLoop to false, you need to end the while loop, and the function, before calling the soloLoop function.


#4

The reason this works is because your soloLoop with the function is a global variable, but within it becomes a local variable with the boolean value (true, false). What @cadecodes is saying is that simply because you can get away with doing this, really doesn't mean you should, unless you had to, which is why we have global and local scopes.

Get creative with names early on so your code works more nicely also.