From 2f76a5743c942d0abdd7d05c400b94930d4aef3f Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Date: Mon, 8 Jun 2026 20:42:09 +0530 Subject: [PATCH] fix mutiple click of start while already start & rapid decreasing of timer --- projects/pomodoro-timer/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/projects/pomodoro-timer/index.js b/projects/pomodoro-timer/index.js index 22b4ede..ebc2c2b 100644 --- a/projects/pomodoro-timer/index.js +++ b/projects/pomodoro-timer/index.js @@ -5,6 +5,7 @@ const timerEl = document.getElementById("timer"); let interval; let timeLeft = 1500; +let start = false; function updateTimer() { let minutes = Math.floor(timeLeft / 60); @@ -17,11 +18,17 @@ function updateTimer() { } function startTimer() { + if(start){ + return; + } + start = true; interval = setInterval(() => { timeLeft--; updateTimer(); - if (timeLeft === 0) { + + if (timeLeft <= 0) { clearInterval(interval); + start = false; alert("Time's up!"); timeLeft = 1500; updateTimer(); @@ -30,9 +37,11 @@ function startTimer() { } function stopTimer() { clearInterval(interval); + start = false; } function resetTimer() { clearInterval(interval); + start = false; timeLeft = 1500; updateTimer(); }