Debugging Checkpoint

BUG-377, Start to Finish

Reasoning Checkpoint

A design challenge, worked through in writing — no auto-grading, just a real attempt.

20–25 min

The Challenge

A week later, a new bug report arrives: BUG-377: "Only 0 seats left!" banner shows when there is still one seat left. Fans see "Only 0 seats left!", think the show is sold out and leave — but one seat is still for sale. It happens on every show, in every browser, locally and in production.

The code: the banner is built by a function seatsLeftMessage(totalSeats, soldSeats). Inside, it calculates const left = totalSeats - soldSeats - 1; and returns "Only " + left + " seats left!" when left is 5 or fewer, and an empty string otherwise.

John asks Anna to handle BUG-377 from start to finish, the way she handled the hour bug.

What Your Answer Needs

  • Say what kind of bug this is (from chapter one), and why.
  • Write the bug ticket: steps to reproduce, expected result and actual result.
  • Describe how you would reproduce and isolate it, including where you'd put a breakpoint and which values you'd watch.
  • Write one specific hypothesis, and the prediction that would prove or disprove it.
  • Write the fix in one sentence.
  • Write at least three test cases (including a regression test for this exact bug) with their assertions, and say which kind of test they are.
Stuck? A Few Hints
  • Try the function in your head with totalSeats = 100 and soldSeats = 99. How many seats are really left?
  • Act 08's dry run and trace table work well here.
  • Think about the edge cases: exactly 0 left, exactly 1 left, exactly 5 left, and 6 left.

Before You Move On

Reproduce, isolate, hypothesise, test, fix — and leave a test behind. If you followed those steps, you debugged this exactly like a professional, even if your wording is different. The "1 seats" problem is a nice reminder that tests often reveal the next small bug too.