Keep getting myself into an infinite loop when i try to fix it


#1

var count = (0)
var loop = function(1){
while(count < 3;){

    console.log("I'm looping");

}

};

loop();


#2

Do it like that, count will always be less than 3. That's why it crashes. There's no limit. So, you must put count++ to make it stop.

Hope it helped!:smiley:


#3

where abouts would i put the count++ ?


#4

Like this:

var count = (0)
var loop = function(1){
while(count < 3;){

console.log("I'm looping");
count++
}
};

loop();

#5

thanks a lot man got myself in a twist trying to fix this one lol :smile:


#6

infact it still wont work for me, i think im just terrible lol


#7

Try this. It's mine:

var count = 0;

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

loop();

I think you got the idea, sooo....


#8

3 thinks:
- values don't need () around them. () are either for function calls after variable names.
- after special keywords like while,for, if function aso
- or like you know from math to increase priority e.g. 2*(3+4)

but here:

var count = (0)

neither of the 3 cases applies so just 0 would be enough.

The second thing is that there is no semicolon needed in the while loop:

while(count < 3;){

the while syntax already makes sure that there is only one statement inside of the loops () so no need for a statement end sign.

And last but not least. this place where you wrote 1:

var loop = function(1){

is reserved for parameters, variable names, so using a value here might cause an error. Also it is not necessary as you don't pass an argument value via the function call in the first place:
loop();