8. When to While and For code problem


#1


8. When to While and When to For
I can't figure out what's wrong with my code


var loop = function () {
    for (var i = 1, i < 23, i++) {
    console.log(i);
    }
};
    
    while(cat >0) {
    console.log("Works");
    cat = false;
    };
    


Replace this line with your code. 



#2

looks like @mtf got you too at the same time so I will let him take over xD


#3

Write two loops in the editor: one while, one for.

Nothing suggested about writing a function. The SCT won't know to call it.

Your for loop is fine. The while loop won't run because cat is not defined.

undefined > 0  => NaN  =>  false

cat = true

or

cat = 1 (or more)

will both work.

true > 0  =>  true

false > 0  =>  false

#4

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