Write multiple setInterval() at once with the same second parameter

I’m making a clock UI that shows analog, digital, and date at the same time. I made a function for each case that requires setInterval(). I wanted to know if I could write them at once in case there were many.

function getAnalog(){
  return 'something';
}
function getDigital(){
  return 'something';
}
function getDate(){
  return 'something';
}

setInterval(getAnalog,1000);setInterval(getDigital,1000);setInterval(getDate,1000);
getAnalog();getDigital();getDate();

>Solution :

You can create another function that calls all of the other functions.

function getAnalog(){
  return 'something';
}
function getDigital(){
  return 'something';
}
function getDate(){
  return 'something';
}
const fn = () => {
    getAnalog();
    getDigital();
    getDate();
};
setInterval(fn, 1000);
fn();

Leave a Reply