JavaScript Tutorial JavaScript Examples JQuery Tutorial CSS Tutorial HTML Tutorial About Us

Countdown Timer

We create a countdown timer with the following JavaScript

function countdown(){

var counter = 10;
var newYearCountdown = setInterval(function(){
document.getElementById("demo").innerHTML = counter;
if (counter ==-1) {
document.getElementById("demo").innerHTML = "HAPPY NEW YEAR!!";
}, 1000);


The setInterval method is to set the interval of the timer, 1000 means 1 second. Besides that, we use the if statement to decrease the counter by 1 after each cycle.


Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy