I’m having trouble using setInterval/clearInterval.
I’ve tried to do something like this: int = setInterval(someFunction(), 1000); but it only call someFunction() once, instead of once every second?
So I tried to do this: int = setInterval("someFunction()", 1000); and it actually works in some way, because it gives me this error Uncaught ReferenceError: someFunction is not defined every second?
Why? D:
setIntervaltakes two arguments: a function, and a time in milliseconds for the time between calls.Your first example is wrong because it doesn’t give a function as argument, it executes the function and passes the result as the first argument. Just change it to
setInterval(someFunction, 1000)and it’ll work.