Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Multiple "Start" Clicks Speed Up the Timer#71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
disha2553 wants to merge2 commits intosahandghavidel:main
base:main
Choose a base branch
Loading
fromdisha2553:fix-bug-timer

Conversation

disha2553
Copy link

Initially, in the Pomodoro Timer project, when we clicked the"Start" button once, the timer would begin as expected.
Butif we clicked "Start" again and again, the timer would run faster than normal. Why?

Because each time we clicked the "Start" button, it started a new interval usingsetInterval,
which means multiple timers were running at the same time — each one reducingtimeLeft every second.
So the countdown speed increased unnaturally.


Step 1: Preventing Multiple Intervals

To solve this, I added the line:

if(interval)return;

at the top of thestartTimer() function.

This line checks if the interval is already running. If yes, it just exits and does nothing.
This means now, even if the user clicks "Start" multiple times, it won’t create new intervals.

Result: The timer no longer speeds up when we click "Start" multiple times.


New Issue After Fix: "Start" Didn’t Work After Stop

After adding that check, a new issue appeared. When we clicked "Stop" and then clicked "Start" again, it wouldn’t resume from where it stopped.

Why did this happen?

Because after callingclearInterval(interval) in thestopTimer() function,
we forgot to reset theinterval variable back tonull.
Sointerval still had a value, and our new condition kept blocking the timer from restarting.


Step 2: Resetting the Interval Variable

To solve this, I added:

interval=null;

at the end of all three functions:
startTimer(),stopTimer(), andresetTimer() — wherever the interval was cleared.
This way, whenever we stop or reset the timer, we also reset theinterval variable, so it becomes ready to start again when needed.


So here I fixed the timer from going faster when we press "Start" multiple times. and also fixed the timer so it can resume again from where i was stopped.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@disha2553

[8]ページ先頭

©2009-2025 Movatter.jp