JSFiddle - React, Tailwind, and code Playground

by Frank Liu

JavaScript

const interval = 500, attempts = 3;
  worker(interval, attempts, callback);
   
  function callback()
  {
  	console.log('hi');
  }
  
  function worker(interval, attempts, callback)
  {
  	let x =1;
    const timer = setInterval( ()=>{ 
      callback();
      if(x >= attempts )
      {         
         clearInterval(timer);
      }
      
      x++; 
    }  , interval);
  }