Timer -> 00 : 00
(function($) { $(".secondsData").click(function(){ var seconds = $(this).data("seconds"); $("#secondInput").val(seconds); $("#minuteInput").val(0); if ($("#play").is(':checked')) console.log('checked'); });
$("#reset").click(function(){ $("#secondInput").val(0); $("#minuteInput").val(0); update_stoper(0, 0); clearInterval(setTimer); });
function update_stoper (m, s) { sec2 = (s < 10) ? "0" + s : s; min2 = (m < 10) ? "0" + m : m; $("#timer span").text(min2 + " : " + sec2); } var sec; var min; var audio = new Audio('https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3'); let setTimer; $("#start").click(function(){ sec = $("#secondInput").val(); min = $("#minuteInput").val(); clearInterval(setTimer); update_stoper(min, sec--); setTimer = setInterval(function () { if (sec === -1) { min--; sec = 59; } if (sec <= 0 && min <= 0) { if ($("#play").is(':checked')) audio.play(); clearInterval(setTimer); } update_stoper(min, sec--); }, 1000); }); }(jQuery));