I make a countdown timer, the timer should start on the 1st day of the month, countdown for 3 days. After 3 days - run again. Every 1st day of the new month should be reset.
(function timer() { var today = new Date(); var start = new Date(2016, 3, 1); var end = new Date(today.getFullYear(), today.getMonth(), start.getDate() + 3); if ( today.getDate() == end.getDate() || today.getDate() == 1 ) { end.setDate( today.getDate() + 3 ); end.setHours(0, 0, 0, 0); } var differenceTime, dd, hh, mm, ss, str; differenceTime = end - new Date(); dd = parseInt( differenceTime / (1000 * 60 * 60 * 24) ); hh = parseInt( differenceTime / (60 * 60 * 1000) ) % 24; mm = parseInt( differenceTime / (1000 * 60) ) % 60; ss = parseInt( differenceTime / 1000 ) % 60; console.log(dd, hh, mm, ss); setTimeout(timer, 1000); })(); Here's what I got. But I'm not sure if I did the right thing. Please indicate errors.