Answer the question
In order to leave comments, you need to log in
How to execute a function every n seconds for x seconds?
There is a function that runs the code every n seconds:
setInterval(function()
{
//некоторые действия функции
},20000);
Answer the question
In order to leave comments, you need to log in
let timer = setInterval(callback, 20000);
setTimeout(clearInterval, 15 * 60 * 1000, timer); // setInterval остановится через 15 минут
Set a counter variable that will record the total elapsed time :). Then turn off the counter :)
https://learn.javascript.ru/settimeout-setinterval
Here is an example of calculating the delay:
let start = Date.now();
let times = [];
setTimeout(function run() {
times.push(Date.now() - start); // запоминаем задержку от предыдущего вызова
if (start + 100 < Date.now()) alert(times); // показываем задержку через 100 мс
else setTimeout(run); // если нужно ещё запланировать
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question