Stuck on While Loop on Review Section


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/2/4?curriculum_id=506324b3a7dffd00020bf661#

I keep getting the error message "Oops, try again. It looks like one of your loops isn't quite right. Check the Hint if you need help!"
Console log prints out my message once, then reads "ReferenceError: count is not defined".

If I remove the "loop();" At the end I pass the course, but I want to know what I've done wrong. I can't see it, though I have painstakingly reviewed so many times! What have I done wrong? TIA.

var helen = 0;
var loop = function(){
while (helen <6) {
    console.log("This should print out five times.  I hope!")
    count++;
}
};
loop ();


#2

Variable helen is defined as 0. Loop is defined as a function. Count isn't defined. What would it increase the value of when the loop runs?


#3

Thanks for that. I understand what you're saying, but in the exercise on looping, that's how it's taught. The code below worked perfectly before in section 4.5, https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/1/1?curriculum_id=506324b3a7dffd00020bf661, I'm puzzled.

var count = 0

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

loop();


#4

Fixed it! I needed to change

count++

to

helen++

Yippee!


#5

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