Help with Practice makes Perfect


#1

I'm having trouble with while loops. If someone could help me, that'd be great! :slight_smile:

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

What am I doing wrong? It just keeps telling me "Looks like you didn't log "I'm looping!" to the console 3 times."


var count = 3

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

loop();

Thanks again, everyone :slight_smile:


#2

Count is never less than 3 if it is 3. Set count to 0 so it can add up to 3.


#3

//Remember to set your condition outside the loop!

var count = 0;
var loop = function() {

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

};

loop();

this doesnt work so could you please point out where its off thanks.


#4

while loop is not like a for loop.

For Loop

for( i=0; i < 10; i++){
     console.log(i);
}

While loop.

var i = 0;
while(i < 10){
     console.log(i)
     i++
}

#5

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