Source code function countdown() { var msg = null; var now = new Date(); var Christmas = new Date(now.getFullYear(), 11, 25); if (now.getMonth() == Christmas.getMonth()) { if (now.getDate() == Christmas.getDate()) { msg = 'Merry Christmas'; } else if (now.getDate() > Christmas.getDate()) { Christmas.setFullYear() = now.getFullYear() + 1; } } if (msg == null) { msg = Math.floor((Christmas.getTime() - now.getTime()) / 1000); } document.getElementById('display').innerHTML = msg; setTimeout(countdown, 1000); } window.onload = countdown;
Example output Seconds left until Christmas: Sorry. No JavaScript! Now you'll never know when Christmas arrives.