settimeout for 3 seconds code example

Example 1: javascript settimeout

setTimeout(function(){
 	alert("Sup!"); 
}, 2000);//wait 2 seconds

Example 2: settimeout javascript

setTimeout(function(){
 	console.log("hello");
}, 3000); //wait for atleast  3 seconds before console logging

Example 3: javascript settimeout

var timeoutID;

function delayedAlert() {
  timeoutID = window.setTimeout(window.alert, 2*1000, 'That was really slow!');
}

function clearAlert() {
  window.clearTimeout(timeoutID);
}

Example 4: onclick timer javascript

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);
});