samedi 23 janvier 2016

Decrementing Button to stop at 1

I am very confused about this one. I am building a pomodoro clock and I already had it running just fine decrementing until 1 and stop there at the adjuster display and in the clock itself. I added a few lines of code and it does not stop at one anymore, it goes to zero, -1 etc. Even after I erased the new lines and tested it no longer works. I know this should be fairly easy but I cannot seem to get it to work properly and stay working. Any help is appreciated.

 <div id="center">
    <p id="title">Pomodoro Clock</p>
    <p id="mytimer">25</p>

    <div class="buttons">
    <button class="btn btn-primary" onClick="start()"><i class="fa fa-clock-o"></i>&nbsp;&nbsp; Start &nbsp;       </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button class="btn btn-warning" onClick="reset()"><i class="fa fa-clock-o"></i>&nbsp; Reset</button>
  </div>
 </div>

  <div id="workArrows">
      <h6>Session Time</h6>
      <button class="btn btn-info arrowbtn" onClick="upWork()"> <i class="fa fa-arrow-up"></i></button>
       <h4 class="arrownum" id="sessiontime">25</h4>
       <button class="btn btn-info arrowbtn" onClick="downWork()"><i class="fa fa-arrow-down"></i></button> 
  </div>

function downWork(){
  var lesswork = 25; //decrease time adjuster
  var decreasetimer = 25; //decrease the clock respectively

  if(lesswork > 1){
  lesswork = document.getElementById("sessiontime").innerHTML;
  lesswork--;
  document.getElementById("sessiontime").innerHTML= lesswork;

  decreasetimer = document.getElementById("mytimer").innerHTML;
  decreasetimer--;
  document.getElementById("mytimer").innerHTML = decreasetimer;

}else{
  lesswork = 1;
  document.getElementById("sessiontime").innerHTML = lesswork;

  decreasetimer = 1;
  document.getElementById("mytimer").innerHTML = decreasetimer;
    }
}

Aucun commentaire:

Enregistrer un commentaire