1

I have a number as minutes say it is 30 minutes and my js/html code is

var countDownTimer = parseInt($("#time").val());
     console.log("Time value is " + countDownTimer);
        function timerFunction() {
            var m = (((countDownTimer*60) / 60) >> 0);
            var s = (countDownTimer % 60);
            $('#tm').text(("00" + m).slice(-2) + ':' + ("00" + s).slice(-2));
            if (countDownTimer == 0) {
             console.log("Time up.");
             $('#tm').text(("00"));
                
            }
            countDownTimer -= 1;
        }

        setInterval(timerFunction, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
Time Left : <span id="tm"></span>

<input type="hidden" id = "time" value="30"/>
                          

when I run the code I don't get desired results please see the weird result and suggest a authentic way to get the job done.

Mini Cascading
  • 83
  • 1
  • 2
  • 12
  • I want the seconds be -- but here the both sides getting affected! – Mini Cascading Mar 14 '16 at 12:22
  • 1
    Lots of resources out there for this: http://www.sitepoint.com/build-javascript-countdown-timer-no-dependencies/, http://stackoverflow.com/questions/20618355/the-simplest-possible-javascript-countdown-timer – Ecnalyr Mar 14 '16 at 12:24
  • Your logic here is very flawed as you subtract 1 from both the minute and second part of the time on each iteration. This question has been asked and solved many times before. See the answer marked as duplicate for a working countdown solution. – Rory McCrossan Mar 14 '16 at 12:29
  • That solves my problem thanks – Mini Cascading Mar 14 '16 at 12:32

0 Answers0