How to set a timer in JavasScript

No Comments

If we want to call a function every 10 seconds using JavaScript we can accomplish it by implementing the following piece of code

window.setInterval('yourfunction()', 1000);
 
function yourfunction(){
alert('test');
 
}

With the code above every 10 seconds a JavaScript function with the name yourfunction will be called that will prompt an alert.

window.setInterval = Evaluates an expression each time a certain number of seconds have elapsed

Image Credits: Photo by Isis França on Unsplash.

Last Updated On March 20, 2018

Related Articles

No results found

Leave a Reply

avatar
  Subscribe  
Notify of
Menu
Copy link