I've been working on a code for a school project and I'm pretty new into JavaScript. I've written code for a timer which is counting down from 40 to 0 in 40 seconds. After that, I want to have another timer but with a different text starting where the first time has been stopped.
But I can't figure out how to do it. I've heard about setInterval
, but I don't know how to apply it..
My code:
<script type="text/javascript">
function countDown(secs, elem) {
var element = document.getElementById(elem);
element.innerHTML = "Word bereid, nog " + secs + " seconde te gaan";
if (secs < 1) {
clearTimeout(timer);
element.innerHTML = '';
}
</script>
secs--;
var timer = setTimeout('countDown('+secs+',"'+elem+'")',1000);
}
<div id="status">
</div>
<script type="text/javascript">
countDown(5, "status")
</script>
</div>