SyntaxError: Unexpected token


#1

I don't know why this code isn't working can someone please help.

var count = 0;

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

loop(count);


#2

Hello!

Let's see...

You put a ";" after

var loop = function( );

Remember the syntax:

var something = function () { 
while ( something ) { do something }

};

The second thing is you forgot to count++

You set the variable to 0. Inside the while you should count++. It will start counting from zero till <3.
You don't need to set count to false. It will stop when it count to 2.

And that loop function in the end should be empty. You're just calling it. No need to pass any values.

Your code should look like this:

var count = 0;

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

loop();

Try it. :wink:


#3

It worked :smile: thanks I think the count++ really messed me up. thanks so much :smile: