Solo flight question


#1



It keeps saying I didn't log what it wanted me to log.


//Remember to make your condition true outside the loop!
var condition = true;

var soloLoop = function(){
    while(condition){
        console.log("Looped once!");
        var condition = false;
  //Your code goes here!
    }
};

soloLoop();


#2

The problem is that inside of your loop, you try to initialize condition again, by putting the var keyword there. the solution is to take away the word var, but the reason why is because that variable is initialized before the loop, so introducing it again just isn't possible.
I hopeed this helped a little bit. I know that you can't initialize the same variable twice, but i don't know how to explain the reasoning behind it.


#3

Inside your function condition is undefined.so your loop will not run.
why undefined?
in javascript you can refer to a variable declared later, without getting an exception. This concept is known as hoisting.variables in JavaScript are in a sense "hoisted" or lifted to the top of the function or statement.

var condition = true;
var soloLoop = function(){
    while(condition){// condition is undifined
        console.log("Looped once!");
        var condition = false;
  //Your code goes here!
    }
};

is implicitly understood as:

var condition = true;
var soloLoop = function(){
var condition = false; //condition is undifined.This concept is known as hoisting
    while(condition){ 
        console.log("Looped once!");
        
  //Your code goes here!
    }
};

variables that are hoisted will return a value of undefined.

so simply remove the var keyword what @kyleaw told you.


#4

Thank you! It makes sense!


#5

Alright makes more sense now, thanks for showing me visually.


#6

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