How to make `setInterval` behave more in sync, or how to use `setTimeout` instead?

I am working on a music program that requires multiple JavaScript elements to be in sync with another. I’ve been using setInterval, which works really well initially. However, over time the elements gradually become out of sync which is bad in a music program. I’ve read online that setTimeout is more accurate, and you can … Read more