I dont know whats wrong


#1

//Remember to set your condition outside the loop!
var count = 0

var loop = function(count){
while(count++){
console.log( "I'm looping!")
}
};

loop(count < 3);


#2

Well here:
loop(count < 3);
you pass a value to the function that gets assigned to the parameter count. Now what is this value?

count < 3

So as you set count to be 0, 0 < 3 therefore the value assigned to count inside the function (which is not the same one outside the function, check shadowing and the function exercise if needed) is `true`. Now as a side effect `true` has a numerical value of 1 (false is 0) so count++ increases this value by 1. And if you google a bit you'll find that all numbers except 0 are treated as true when used in a condition so you're while loop is essentially an infinite loop.
So really take the take and review how functions and loops work before you go on.

PS: Also outside the loop could still mean inside the function.


#3

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