Using setTimeout for clearInterval is not an ideal solution. It will work, but it will run your setTimeout on every interval. This is normal if you are only clearing the interval, but it can be bad if you are executing other code, in addition to clearing the interval. The best solution is to use a counter. If your interval fires every 1000 ms / s, then you know if it shoots 5 times, it was 5 seconds. It is much cleaner.
count=0; var x=setInterval(function(){
source share