How to stop a Javascript Timer after the second countdown? -


i trying create pomodoro clock (a countdown timer 25-minutes of productivity , 5-minute countdown of break time), , having trouble stopping break time countdown.

here's javascript have far:

function starttimer(duration, display) {     var timer = duration, minutes, seconds;     var countdown = setinterval(function () {         minutes = parseint(timer / 60, 10)         seconds = parseint(timer % 60, 10);          seconds = seconds < 10 ? "0" + seconds : seconds;          display.textcontent = minutes + ":" + seconds;         if (--timer < 0) {             clearinterval(countdown);              var breakclock = function() {                  $("#title").text(function(i, text){        return text === 'breaktime' ? 'productive countdown' : 'breaktime'             });                var fiveminutes = 60 * .05,                   display = document.queryselector('#time');              starttimer(fiveminutes, display);               if (--timer < 0) {                   clearinterval(this.countdown);              }              };            breakclock();             }     }, 500); }                   $(".startclock").click(function(){     var twentyfiveminutes = 60 * .25,         display = document.queryselector('#time');     starttimer(twentyfiveminutes, display); }); 

here's codepen: http://codepen.io/cenjennifer/pen/pjzbvy?editors=101

fyi: reduce time can test functionality.

change:

clearinterval(this.countdown); 

to:

clearinterval(countdown); 

the this keyword not needed countdown variable local variable of parent scope of breakclock() function.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -