Stumped on While loops in JS - code won't run (6. solo flight)


#1


Hi everyone! I'm completely stumped as to why this won't work. I'm afraid that I'm missing something obvious. Could anyone out there please enlighten me?? Cheers!


Intro to While loops is JS - 6. Solo Flight


Oops, try again. Did you log 'Looped once!' to the console?

var intCond = true;

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


#2

The variable was declared already so we never do that again, only redefine it.

intCond = false;

There is no parameter needed for this function. By adding it we create a new problem known as shadowing. The loop cannot see the actual value of the global variable because the locally declared variable is shadowing or blocking access.

var soloLoop = function () {

Continuing from above, the consequence of the locally declared variable is that it is undefined, which evaluates to false so the loop never ran.


#3

Thanks so much mtf! Great explanations, really appreciate it!


#4

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