JavaScript setInterval
setInterval(function(){
console.log("Oooo Yeaaa!");
}, 2000);//run this thang every 2 seconds
Grepper
setInterval(function(){
console.log("Oooo Yeaaa!");
}, 2000);//run this thang every 2 seconds
setTimeout(function(){
//code goes here
}, 2000); //Time before execution
function func(){
console.log("Ran")
}
setInterval(func,1000)//Runs the "func" function every second
setInterval(function(){
console.log("Hello World!");
}, 2000); //run this script every 2 seconds(specified in milliseconds)
setInterval(function() {
//Your code
}, 1000); //Every 1000ms = 1sec
// variable to store our intervalID
let nIntervId;
function changeColor() {
// check if already an interval has been set up
if (!nIntervId) {
nIntervId = setInterval(flashText, 5);
}
}
function flashText() {
const oElem = document.getElementById("my_box");
if (oElem.className === "go") {
oElem.className = "stop";
} else {
oElem.className = "go";
}
}
function stopTextColor() {
clearInterval(nIntervId);
// release our intervalID from the variable
nIntervId = null;
}
document.getElementById("start").addEventListener("click", changeColor);
document.getElementById("stop").addEventListener("click", stopTextColor);