Eren55
0
Q:

onclick timer javascript

//single event i.e. alarm, time in milliseconds
var timeout = setTimeout(function(){yourFunction()},10000);
//repeated events, gap in milliseconds
var interval = setInterval(function(){yourFunction()},1000);
9
//to repeat a function here, MyTimer at every 1000 ms ie 1 sec use this
 var myVar = setInterval(myTimer, 1000);
//replace myTimer with your function, and 1000 with the no of seconds between each function call
// used it run refresh function to refresh a page at 300000ms ie every 5 minutes
//var myVar = setInterval(refreshPage, 300000);
function myTimer() {
  var d = new Date();
  document.getElementById("demo").innerHTML = d.toLocaleTimeString();

} 
0
document.getElementById("gameStart").addEventListener("click", function(){
    var timeleft = 15;

    var downloadTimer = setInterval(function function1(){
    document.getElementById("countdown").innerHTML = timeleft + 
    " "+"seconds remaining";

    timeleft -= 1;
    if(timeleft <= 0){
        clearInterval(downloadTimer);
        document.getElementById("countdown").innerHTML = "Time is up!"
    }
    }, 1000);

    console.log(countdown);
});
0

New to Communities?

Join the community