I don’t understand how to pause the clock. I think I have the basic premise right, but it’s not working. I’ve tried putting the pause function both inside and outside of the time function, with no change.
Code so far:
var work = parseInt($("#wtime").html());
var brk = parseInt($("#btime").html());
var disp = parseInt($("#display").html());
var sound = $("#sound")[0];
var counting = 0;
$("#reset").hide();
$("#wdec").click(function(){
if (work >= 1){
work -= 1;
}
$("#wtime").html(work + ":00");
$("#display").html(work + ":00");
});
$("#winc").click(function(){
if (work <= 55){
work += 5;
}
$("#wtime").html(work + ":00");
$("#display").html(work + ":00");
});
$("#bdec").click(function(){
if (brk >= 1){
brk -= 1;
}
$("#btime").html(brk + ":00");
});
$("#binc").click(function(){
if (brk <= 25){
brk += 5;
}
$("#btime").html(brk + ":00");
});
$("#start").click(function(){
var countdown = setInterval(time, 1000);
var breaktime;
work *= 60;
brk *= 60;
function time(){
work -= 1;
if (work === 0){
clearInterval(countdown);
sound.play();
breaktime = setInterval(brktime, 1000);
}
if (work%60 >= 10){
$("#display").html(Math.floor(work/60) + ":" + (work%60));
} else {
$("#display").html(Math.floor(work/60) + ":0" + (work%60));
}
$("#start").hide();
function brktime(){
brk -= 1;
if (brk === 0){
clearInterval(breaktime);
sound.play();
$("#start").hide();
$("#reset").show();
}
if (brk%60 >= 10){
$("#display").html(Math.floor(brk/60) + ":" + (brk%60));
} else {
$("#display").html(Math.floor(brk/60) + ":0" + (brk%60));
}
}//end of brktime
}//end of time
$("#pause").click(function(){
if (counting == 0){
counting == countdown;
} else {
clearInterval(counting);
counting = 0;
}
});
});//end of start
$("#reset").click(function(){
work=5;
brk=5;
disp=5;
$("#wtime").html(work + ":00");
$("#btime").html(brk + ":00");
$("#display").html(disp + ":00");
$("#reset").hide();
$("#start").show();
});
});//end of doc ready