From 15b688456017bbdbbff27515b59a77694a0f6978 Mon Sep 17 00:00:00 2001 From: Valik Date: Wed, 22 Nov 2023 20:56:51 +0100 Subject: [PATCH] Fix timer reset issue --- src/js/02-timer.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/js/02-timer.js b/src/js/02-timer.js index 14c503c..d99c87b 100644 --- a/src/js/02-timer.js +++ b/src/js/02-timer.js @@ -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; @@ -80,6 +80,11 @@ function convertMs(ms) { } function updateCountdown() { + if (!endDate) { + clearInterval(intervalId); + return; + } + const currentDate = new Date().getTime(); const timeDifference = endDate - currentDate; @@ -95,6 +100,8 @@ function updateCountdown() { Notiflix.Notify.success("Timer has ended!"); + endDate = null; + return; } @@ -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; });