- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Weekly Countdown?
I have a bit of code that I got together.
My ultimate goal is to have a countdown timer that automatically repeats every week when it reaches 0.
So basically always be counting down to Sunday at 6pm. When reaching Sunday at 6, start over.
Any ideas ?
http://codepen.io/anon/pen/pGlIb (current)
Think I might have got it. Input? Better method?
Your second PEN isn’t working but it appears the one you linked in the OP is behaving properly.
I notice you’re already checking the date as a comparison in your setInterval function: bravo!
Some general info on why this is good:
SetInterval is not guaranteed to execute your callback functions exactly at the set time interval – it’s just guaranteed to be at least X milliseconds later (where x is the delay.) There is a chance of slight variance.
http://ejohn.org/blog/how-javascript-timers-work/ (older, but good)
http://stackoverflow.com/questions/11042510/javascript-duration-of-animation-isnt-exact (see accepted answer)
One strategy for circumventing this annoyance is to check the date in your setInterval and compare it to when you started counting and adjust accordingly. This ensures your countdown will be completely accurate.
http://www.andrewduthie.com/post/a-self-correcting-setinterval-alternative/