javascript - How can I make a timer that starts at 02:00 reaches 00:00 and then restarts at 06:00 -


how can make timer starts counting down @ 02:00 , when reaches 00:00 restart @ 06:00 again counts down until reaches 00:00 , starts counting 00:00. have code when reaches 00:00 counts up.

    var direction = 'down';      var mins = 30;      var secs = mins * 60;        function colorchange(minutes, seconds) {        var minutes = document.getelementbyid('minutes');        var seconds = document.getelementbyid('seconds');        var colon = document.getelementbyid('divide');          var color;        if (direction == 'up') {          color = 'black';        } else if (secs <= 30) {          color = 'red';        } else if (secs <= 59) {          color = 'orange';        }        minutes.style.color = seconds.style.color = colon.style.color = color      }        function getminutes() {        // minutes seconds divided 60, rounded down        mins = math.floor(secs / 60);        return ("0" + mins).substr(-2);      }        function getseconds() {        // take mins remaining (as seconds) away total seconds remaining        return ("0" + (secs - math.round(mins * 60))).substr(-2);      }        function countdown() {        setinterval(function() {          var minutes = document.getelementbyid('minutes');          var seconds = document.getelementbyid('seconds');            minutes.value = getminutes();          seconds.value = getseconds();          colorchange(minutes, seconds);            if (direction == 'down') {            secs--;            if (secs <= 0) {              direction = 'up';            }          } else if (direction == 'up') {            secs++;          }        }, 1000);      }          countdown();
<div id="timer" style="width: 90%;">    <input id="minutes" type="text" style="width: 90%; border: none; background-   color:none; font-size: 300px; font-weight: bold; position: fixed; bottom: 30%;right: -2%;">    <input id="seconds" type="text" style="width: 90%; border: none; background-color:none; font-size: 300px; font-weight: bold; position: fixed; bottom: 30%;right: -42%;">    <span id="divide" style="width: 90%; border: none; background-color:none; font-size: 300px; font-weight: bold; position: fixed; bottom: 30%; padding-left: 42%;">:       </span>  </div>

var direction = 'down';  var first = true; // added  var mins = 2; // changed  var secs = mins * 60;    function colorchange() {    var minutes = document.getelementbyid('minutes');    var seconds = document.getelementbyid('seconds');    var colon = document.getelementbyid('divide');      var color="black";    if (secs <= 30) {      color = 'red';    } else if (secs <= 59) {      color = 'orange';    }    minutes.style.color = seconds.style.color = colon.style.color = color  }    function getminutes() {    // minutes seconds divided 60, rounded down    mins = math.floor(secs / 60);    return ("0" + mins).substr(-2);  }    function getseconds() {    // take mins remaining (as seconds) away total seconds remaining    return ("0" + (secs - math.round(mins * 60))).substr(-2);  }    function countdown() {    setinterval(function() {      var minutes = document.getelementbyid('minutes');      var seconds = document.getelementbyid('seconds');      if (direction == 'down') {        secs--;        if (secs <= 0) {          if (first) { // added            first=false;            mins = 6;            secs = mins*60;          }          else direction = 'up'; // added        }      } else if (direction == 'up') {        secs++;      }      minutes.value = getminutes();      seconds.value = getseconds();      colorchange();                }, 1000);  }      countdown();
<div id="timer" style="width: 90%;">    <input id="minutes" type="text" style="width: 90%; border: none; background-   color:none; font-size: 300px; font-weight: bold; position: fixed; bottom: 30%;right: -2%;">    <input id="seconds" type="text" style="width: 90%; border: none; background-color:none; font-size: 300px; font-weight: bold; position: fixed; bottom: 30%;right: -42%;">    <span id="divide" style="width: 90%; border: none; background-color:none; font-size: 300px; font-weight: bold; position: fixed; bottom: 30%; padding-left: 42%;">:       </span>  </div>


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -