if (hour is > 9am && hour is < 8pm){
setInterval(myFunction,60000)
}
else {
setInterval(myFunction,100000)
}
I want to execute myFunction less often after 8pm but the problem is that if user landed on the page at 2 pm it will always execute every minute unless script is refreshed. How can this be solved?
it would still be executing every 1 minute because I would only take an hour out of the Date object and therefore hr would be 7.
Reason I ask is that I want to execute myFunction more often while the office is open and less often when the office is not open. If the user lands on the page during the opening time and stays there beyond opening into the closing time myFunction will still execute every 1 minute because JS still thinks the hour is what it was when page was loaded
I know but even if I use that function do I have to recheck the time every time before execution?
if (hours >= 15) {
//check hour of the day here??
setTimeout(executeEveryMinute, 1200000);
} else {
//check hoir of the day here?
setTimeout(executeEveryMinute, 60000);
}