5/11: Practice Makes Perfect


#1

I can't figure out what I'm doing wrong. Can someone help me? Here's my code:

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

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

What am I doing wrong? Any help appreciated :smile:


#2

you forgot to set the count to 0 so it would be var count = 0


#3

I tried and it said this :"Oops, try again. Are you logging 'I'm looping!' to the console three times?"

Here's what I changed it to:

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

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


#4

you also need to call the loop function by loop();


#5

sorry about that, you dont need to semi-colon on the count++, but you do need it at the last curly bracket to finish off the code, so it should look like this, sorry i missed that

var count = 0

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

loop();


#6

actually the semicolon after the count++ is fine, nothing wrong with this one.


#7

I made it Like This and it works.

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

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

loop();