So if I had some code, and I wanted to print this certain variable every 1 second (or any number, but constantly updating) how would I do that? I need a variable to be printed onto the page every 1 second, and I may need to do similar things with other variables later, but I'm just not sure how I would do this.
Asked
Active
Viewed 61 times
-1
-
https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Timers – Tareq Jul 28 '17 at 22:48
2 Answers
0
Set interval can do this. If you want to delay it for one time only, use setTimeout. See https://www.w3schools.com/js/js_timing.asp
let SECOND = 1000;
let variableToChange = 0;
setInterval(function(){
variableToChange++;
}, SECOND)

Chase W.
- 1,343
- 2
- 13
- 25
-1
const callbackFunction = function () { /*do something*/ };
setInterval( callbackFunction, 1000); //callbackFunction is invoked every 1000ms (1s).

karthiks
- 7,049
- 7
- 47
- 62

Farshid Rezaei
- 751
- 2
- 10
- 34
-
Add some details which show that it is a helpful statement in your answer. – Jaffer Wilson Jul 29 '17 at 04:18