Simple javascript console log (FireFox)

I am trying to register a value change in the console (Firefox / Firefly, mac).

if(count < 1000) { count = count+1; console.log(count); setTimeout("startProgress", 1000); } 

This returns a value of 1. It stops after that.

Am I doing something wrong or is something else affecting it?

+6
javascript firefox
source share
3 answers

You have no cycle. Only a conditional statement. Use while .

 var count = 1; while( count < 1000 ) { count = count+1; console.log(count); setTimeout("startProgress", 1000); // you really want to do this 1000 times? } 

it's better:

 var count = 1; setTimeout(startProgress,1000); // I'm guessing this is where you want this while( count < 1000 ) { console.log( count++ ); } 
+10
source share

I think you are looking for a while :

 var count = 0; while(count < 1000) { count++; console.log(count); setTimeout("startProgress", 1000); } 
+1
source share

As other answers show, if vs while is your problem. However, the best approach to this would be to use setInterval() , for example:

 setinterval(startProcess, 1000); 

This does not stop at 1000 calls, but I assume that you are just doing this for testing at the moment. If you need to stop doing this, you can use clearInterval() , for example:

 var interval = setinterval(startProcess, 1000); //later... clearInterval(interval); 
+1
source share

All Articles