thecodezone.
The Code Zone
← Back to the Developer Playbook

Code Zone Bug Lab / Episode 03

The Counter That Skips

One click should add one. Rob’s counter jumps from 0 to 2.

DEV-146 · Events · tracing execution15–20 minutesNo setup or account required
One click changes a counter from zero to two while both event routes respond.
One click changes a counter from zero to two while both event routes respond.

Your sprint ticket · In progress · DEV-146

The Counter That Skips.

Customer report: I clicked Add one once, but the counter increased by two.

Steps to reproduce

  1. Start at 0.
  2. Click Add one once, then twice more.
  3. Compare clicks with the count and Console messages.

Keep the existing counter and Reset behavior. Styling is outside this ticket.

Acceptance criteria

  • One click changes 0 to 1.
  • Three clicks change 0 to 3.
  • Reset returns the count to 0.
  • After Reset, the next click changes 0 to 1.

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

Reproduce → inspect → hypothesize → verify

Take the ticket.

Reproduce the reported behavior before editing. Read the Console and inspect the JS tab. Explain one hypothesis, make a focused change, then use Check challenge below the code screen. Edits update the preview. 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.

    The same function is registered on both the button and its parent panel. The click bubbles from button to panel, so it runs twice. Remove the parent panel click listener and keep the button listener. Retest Reset and repeated clicks.

    Try first. Reveal one clue at a time.

    Need a lead?

    1. Follow one click.

    How many “increment handler ran” messages appear for one click?

    2. Inspect event registration.

    Find every place addEventListener attaches the same click handler.

    3. Keep one listener.

    Register increment once. Removing both listeners would leave the button broken.

    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) ↗