1

I dont know whats going on. Heres my code:

   setInterval(testI(),1000);

   function testI(){
        console.log("I ran");
   }

It then runs the function once but does not repeat. I tried running it in both chrome and firefox and got the same result. I am very confused.

Caelan
  • 23
  • 2
  • 1
    Does this answer your question? [Calling functions with setTimeout()](https://stackoverflow.com/questions/3800512/calling-functions-with-settimeout) – Heretic Monkey May 01 '21 at 21:03

1 Answers1

5

Try this:-

 setInterval(testI, 1000);

You have to pass the function reference here. Then setInterval function will invoke it. But right now you are invoking the function here instead of passing reference.

Showrin Barua
  • 1,737
  • 1
  • 11
  • 22