thecodezone.
The Code Zone
← Back to the Developer Playbook

Code Zone Bug Lab / Episode 17

The Countdown That Never Stops

The timer reaches zero—and keeps counting into negative numbers.

DEV-160 · Intervals · conditions · cleanup15–20 minutesNo setup or account required
A countdown continues from three through one to negative one.
A countdown continues from three through one to negative one.

Your sprint ticket · In progress · DEV-160

The Countdown That Never Stops.

Customer report: My countdown reaches 0, then keeps showing -1, -2, and lower.

Steps to reproduce

  1. Keep the start value at 3.
  2. Click Start countdown and wait a few seconds.
  3. Watch the display after it reaches zero.

Make a focused behavior fix. Styling and adding unrelated features belong to another ticket.

Acceptance criteria

  • A countdown from 3 displays 2, 1, then 0.
  • The countdown never becomes negative.
  • The active interval is cleared at zero.
  • Starting at 0 does not start an interval.
  • Reset stops an active countdown and restores the entered start value.

Learning demo only. No real accounts, purchases, authentication, or external requests.

Reproduce → inspect → hypothesize → verify

Take the ticket.

Reproduce the bug before editing. Inspect the Console and the JS tab. Explain one hypothesis, change the relevant code, then use Check challenge below the editor. Test the full ticket, not only the starter example. Reveal hints one at a time if needed.

Checking account and saved lab work…

Sign in to sync across devices

Loading the JavaScript and HTML editor…

Pass the checks or make three attempts to unlock an explained example.

Ready to test? Choose “Check challenge” after investigating.

    Open starter in a separate tab

    Code and prediction notes recover in this browser and sync when signed in. Instructor examples stay separate. Reset replaces code, not prediction notes.

    One possible solution

    Compare this approach with your own. Opening it does not change your code or mark the exercise complete.

    After decreasing remaining, handle remaining <= 0: clamp it to zero, call clearInterval(timerId), and set timerId = null. Then render the count. The tests use a controlled interval scheduler so zero and cleanup can be checked instantly without waiting for real seconds. The preview itself ticks once per second.

    Try first. Reveal one clue at a time.

    Need a lead?

    1. Watch what happens at zero.

    The interval runs repeatedly until someone clears it. Does tick ever stop the interval?

    2. Stop the scheduled work.

    clearInterval(timerId) cancels future ticks. Keep the displayed value at zero.

    3. Release the timer handle.

    After reaching zero, clear the interval and set timerId to null. Verify Reset and a fresh Start too.

    Your lab report

    Show your reasoning.

    “I expected… I observed… The console showed… My hypothesis was… I changed… I verified…”

    Use Check challenge for automated behavior checks. Passing checks are useful evidence, not a complete code review.

    Give others room to investigate: label solutions as spoilers.

    Share your lab report on SKOOL (new tab) ↗