I just practice using Interval and clearInterval methods. I want to restart setInterval after calling clearInterval.
Here is the code
var ppp = document.getElementById('pp');
var timer = setInterval(Func, 1000);
var seconds = 0;
function Func() {
ppp.innerText = seconds++;
if (seconds > 10) {
clearInterval(timer);
}
if (seconds == 10) {
restart();
}
}
function restart() {
seconds = 0;
timer = setInterval(Func, 1000);
}
<p id="pp"></p>
Output
not counting by one by one Expected 0 1 2 3 4 5 6 7 8 9 10 and restart from 0~10