Home » Javascript » How to display count down in loop javascript?

How to display count down in loop javascript?

Posted by: admin August 19, 2018 Leave a comment

Questions:

i have this in php file

<body>
     <span id="time"></span> 
</body>
<?php $var0 = 1; ?>

and this in javascript

   function startTimer(duration, display) {
        var timer = duration, minutes, seconds;
        setInterval(function () {
            minutes = parseInt(timer / 60, 10)
            seconds = parseInt(timer % 60, 10);

            minutes = minutes < 10 ? "0" + minutes : minutes;
            seconds = seconds < 10 ? "0" + seconds : seconds;
            if(minutes <= 0){
                 display.textContent = seconds + "s";
            }else{
                 display.textContent = minutes + "m " + seconds + "s";
            }


            if (--timer < 0) {
                timer = duration;
            }
        }, 1000);
    }
    window.onload = function () {

            var fiveMinutes = 60 * <?php echo $var0; ?>,
            display = document.querySelector('#time');
            startTimer(fiveMinutes, display);

    };

it works perfectly but i need to display this in a loop for example i have 2 variables and i want to display two times with new line .. or when i have n variables i got n new line with the time of the variables that will hold the information from database.. thank you

Answers: