0
Q:

javascript time interval

setInterval(function(){ 
	console.log("Oooo Yeaaa!");
}, 2000);//run this thang every 2 seconds
51
function func(){
  console.log("Ran")
}
setInterval(func,1000)//Runs the "func" function every second
9
setInterval(function() {
  //Your code
}, 1000); //Every 1000ms = 1sec
2

 var myVar;

function myFunction() {
  myVar = setInterval(alertFunc, 3000);
}

function alertFunc() {
  alert("Hello!");
}

 
0

 setInterval(function(){ alert("Hello"); }, 3000);

 
0
<!DOCTYPE html>
<html>
<head>
    <title>setInterval</title>
    <script type="text/javascript">
      
        let interval;
      
        function startInterval(){
          interval = setInterval(appendDateToBody, 1000);
          console.log(interval);
        }
 
        function appendDateToBody() {
            document.body.appendChild(
                document.createTextNode(new Date() + " "));
        }

        function stopInterval() {
            clearInterval(interval);
          console.log(interval);
        }
    </script>
</head>
<body>
    <input type="button" value="Stop" onclick="stopInterval();" />
  <input type="button" value="Start" onclick="startInterval();" />
</body>
</html>
0

New to Communities?

Join the community