Solo Flight | Question


#1

I past this lesson, but I got a question. Why do I need to write 'real = false' instead of 'var real = false' after the console.log?
Just want to know the reason.
Thanks

Code:

//Remember to make your condition true outside the loop!
var real = true
var soloLoop = function(){
while(real){
console.log("Looped once!");
real = false;
}

};

soloLoop();


#2

otherwise real will stay true which means you have an infinity loop


#3

Also you don't have to use 'var real = false;' because you only need to declare a variable with 'var' the first time you use it.


#4

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