how to create a 30 seconds timer using js

JavaScript
var timeLeft = 30;
var elem = document.getElementById('some_div'); //where you want to show timer
var timerId = setInterval(countdown, 1000);

function countdown() {
    if (timeLeft == -1) {
        clearTimeout(timerId);
        doSomething();
    } else {
        elem.innerHTML = timeLeft + ' seconds remaining';
        timeLeft--;
    }
}

function doSomething() {
    alert("Hi");
}
Source

Also in JavaScript: