Demo of modulus function resetting incremental counter in JavaScript
<script>
var speed=1000; // For one second duration it is 1000
var counter_value=30; // change this value
var ms=0;
function my_function(){
document.getElementById("d1").innerHTML="<h2>"+ ms + "</h2>"; // display the counter
ms=ms+1; // increment by 1
if(ms % counter_value ==0){
ms=0;
}
//timer to trigger my_function() at an interval of millseconds set by speed valirable//
my_time=setTimeout('my_function()',speed);
}
/////////
my_function();
</script>