Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading