I am currently working on the pomodoro clock project, and I found a great API that has been very useful (flipclock.js). The problem I am currently having is that I cannot seem to get the break timer to start when the work timer ends, even when I add a conditional that should start that timer when the work timer goes to zero. Additionally, the work timer doesn’t stop when it gets to zero, but continues counting, upwards. How can I solve these problems? Any specific examples would be greatly appreciated.
Here is the javascript:
clock = $(’.clock’).FlipClock({
clockFace: ‘MinuteCounter’,
autoStart: false,
callbacks: {
stop: function() {
$(’.message’).html(‘Time to take a break!’)
}
}
});
break_clock = $(’.break_clock’).FlipClock({
clockFace: ‘MinuteCounter’,
autoStart: false,
callbacks: {
stop: function() {
$(’.message’).html(‘Get back to work!’)
}
}
});
time = 25*60;
clock.setTime(time);
$("#btn2").on(“click”, function() {
time += 60;
clock.setTime(time);
});
$("#btn3").on(“click”, function() {
time -= 60;
clock.setTime(time);
});
$("#btn4").on(“click”, function() {
time = 25*60;
clock.setTime(time);
});
var break_time = 300;
break_clock.setTime(break_time);
$("#btn5").on(“click”, function() {
break_time += 60;
break_clock.setTime(break_time);
});
$("#btn6").on(“click”, function() {
break_time -= 60;
break_clock.setTime(break_time);
});
$("#btn1").on(“click”, function() {
clock.setCountdown(true);
clock.start(function() {
if(clock.getTime()===0){
clock.stop();
}
});
console.log(clock.getTime());
});
If that is too hard to read on here, the link to the codepen is here:
Also, here is the flipclock.js api link for reference:
http://flipclockjs.com
Thanks!