JavaScript Program to Create Count Down Timer in JavaScript

Write a JavaScript program to create count down timer in JavaScript.



Source Code
<html>
<head>
    <title>setInterval() method</title>
    <script type="text/javaScript">
        var count;
        var panel;
        var timer;
        function init()
        {
            count = 10;
            panel = document.getElementById('panel');
            timer = setInterval('countDown()', 1000);
        }
        function countDown()
        {
            if(count == 0) 
            {
                panel.innerHTML = 'TIME UP :-(';
                clearTimeout(timer);
            }
            else 
            {
                panel.innerHTML = count;
                count--;
            }
        }
    </script>
</head>
<body onload="init()">
<h2 id="panel">Count down begins...</h2>
</body>
</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store