Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple javascript console log (FireFox)

I'm trying to log the change of a value in the console (Firefox/Firefly, mac).

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

This is only returning the value 1. It stops after that.

Am I doing something wrong or is there something else affecting this?

like image 471
Kevin Brown Avatar asked Jun 15 '10 21:06

Kevin Brown


2 Answers

You don't have a loop. 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?
}

Better:

var count = 1;
setTimeout(startProgress,1000); // I'm guessing this is where you want this
while( count < 1000 ) {
    console.log( count++ );
}
like image 65
Ken Redler Avatar answered Oct 06 '22 17:10

Ken Redler


I think you are looking for while loop there:

var count = 0;
while(count < 1000) {
  count++;
  console.log(count);
  setTimeout("startProgress", 1000);
}
like image 39
Sarfraz Avatar answered Oct 06 '22 17:10

Sarfraz