Skip to content

Commit

Permalink
Fix timer reset issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Valik3201 committed Nov 22, 2023
1 parent d15f094 commit 15b6884
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/js/02-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const resetBtn = document.querySelector("button[data-reset]");
startBtn.disabled = true;
resetBtn.disabled = true;

let endDate;
let endDate = null;
let intervalId;
let selectedDate;

Expand Down Expand Up @@ -80,6 +80,11 @@ function convertMs(ms) {
}

function updateCountdown() {
if (!endDate) {
clearInterval(intervalId);
return;
}

const currentDate = new Date().getTime();
const timeDifference = endDate - currentDate;

Expand All @@ -95,6 +100,8 @@ function updateCountdown() {

Notiflix.Notify.success("Timer has ended!");

endDate = null;

return;
}

Expand Down Expand Up @@ -134,4 +141,6 @@ resetBtn.addEventListener("click", function () {
document.querySelector("[data-hours]").textContent = "00";
document.querySelector("[data-minutes]").textContent = "00";
document.querySelector("[data-seconds]").textContent = "00";

endDate = null;
});

0 comments on commit 15b6884

Please sign in to comment.