5. Practice makes perfect (Unexpected token)


#1

All try - nothing(

var count === 0;

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

loop();

#2

here === compares count to 0 but as this is the declaration of count, count has no value yet and var + value isn't allowed either so probably this is the problem just use var count = 0; instead. Also it would really help if you could format your code as code by using 3 backtiks before and after your code (just press edit to see how it is done) and by giving some more information about the problem itself. Thank you.


#3

Ty!) I see my mistake(


#4

hey sorry for bringing this up again, but i don't understand about the loop code at the last line. what is the function? thanks for the answers, really appreciated :slightly_smiling:

	//Your code goes here!
	console.log( "I'm looping!");
	count++;
}

};

loop(); // this bro over here. what this one supposed to do?


#5

Well the loop in this example is nested in side of a function:

var loop = function(){
    ...
}

As you've learned in lesson 3 functions are code fragments that are not executed directly but rather run when they are called. With the advantage that you can call them whenever you want and as often as you like, without having to rewrite the code. All you need to do to run the function is a function call like this: loop(); consisting of the function name (loop) and () appended to it. For more complex function you could as well have parameters (variables in the () after the function key word) and arguments (values in the () of the function call) to pass values to the function but for this simple example it's just about getting the code to run so no parameters and no arguments. I'm not sure why you exactly need the function in this exercise but as said it is just a framework in which you write you're code; maybe it is easier for the test function to run a function than to run regular code. Hope this makes some sense to you. Good Luck and if there are questions left just ask :slightly_smiling: