3

I have developed a countdown timer function.

This function works fine. But the problem is it goes through the minus value too. So I want to stop the counting when its come to the 00:00:00. How can I do this.please help me?

Javascript

function initCountdown() {

 if( seconds == 0 && minutes == 0 && hours == 0 ){
      clearInterval( interval ); }
 if (seconds < 10) {
      outputElement.innerHTML = hours + ": " + minutes + ": " + "0" + seconds + " ";
 } else {
      outputElement.innerHTML = hours + ": " + minutes + ": " + seconds + " "; }} 
  function count(){
        time[2]--;
       if (time[2] == -1) {
          time[1]--;
          time[2] = 59
       }
    if (time[1] == -1) {
          time[0]--;
          time[1] = 59
         }
        print();
      }
   var outputElement = document.getElementById('demo');
   var time = document.getElementById("picker-dates1").value;
   time = time.split(':'); }

HTML

 <input type = "text" id = "picker-dates1"/>
 <P id="demo"></p>
4
  • what is the purpose of clearInterval function? Is it resetting the clock? Commented May 3, 2018 at 6:35
  • I don't see where you define seconds, minutes or hours from time[] Commented May 3, 2018 at 6:36
  • There's an extra bracket in outputElement.innerHTML = hours + ": " + minutes + ": " + seconds + " "; }} Commented May 3, 2018 at 6:38
  • Your script is not working (I tried on mozilla) Commented May 3, 2018 at 7:00

1 Answer 1

1

Replace print(); with if (time[0] >= 0) { print(); }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.