Please help (while loops)


#1


var count = 0;

var loop = function(count){
while(count){
//Your code goes here!
console.log("I'm looping!");
}
};

loop(count);


#2

Unclear what the problem is


#3

i think you posted in the wrong place. this is for git lessons.


#4

So, I'm guessing you're looking into this lesson: https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/1/1?curriculum_id=506324b3a7dffd00020bf661

Your loop does not work because the while condition is wrong. Remember that "as long as the condition evaluates to true, the loop will continue to run. As soon as it's false, it'll stop." In this case while(count) neither evaluates to true nor to false. (Technically, it evaluates to 0 === true which is false, and if I'm right, it would not loop at all)

Also remember what you learnt in for loops! :slight_smile:

for (var i = start; i < end; i++) {
  // do something
}

The while condition is not that different. After setting your count to 0, you need to provide a condition for it such that it evaluates to true/false, and then break out of the loop after three times.

Finally, loop(count) would mean loop(0), which does not provide any meaning for the computer. A function does not always need to have parameters! They only need parameters when they need to utilize the value to do something (for instance, value * 2, but in this case, simply calling loop is sufficient to activate the function.


#5

thank you :heart_eyes:


#6

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