Pinpoint the Failing Branch with a Step Trace
Scenario
Input: freeSeats = 2, hasPermission = false, isMaintenance = false. Expected: false. Actual buggy code returned true. Trace the buggy function line by line.
- 1Step 1 · Check if isMaintenance is true
- 2Step 2 · Check freeSeats > 0 || hasPermission
- 3Step 3 · Return decision
Try it yourself
Step through each decision to find the exact branch where actual diverges from expected.
| Case | State after the step |
|---|---|
| Step 1 · Check if isMaintenance is true | — |
| Step 2 · Check freeSeats > 0 || hasPermission | — |
| Step 3 · Return decision | — |
Reveal the explanation
- Step 1 · Check if isMaintenance is true
isMaintenance is false → continue to next check (matches expected).
- Step 2 · Check freeSeats > 0 || hasPermission
Divergence found! Buggy code used OR instead of AND, so freeSeats = 2 made it true.
- Step 3 · Return decision
Buggy code returns true instead of false; root cause is isolated to Step 2.
A step trace replaces random edits with proof. Once you see the first line where the actual path splits from the expected path, you know the exact line to fix.
Your turn
Trace a library checkout bug where (isAvailable=false, borrowedCount=1) wrongly returned true using `if (isAvailable || borrowedCount < 3)`.
Common mistake Changing multiple lines at once before finding which branch first disagreed with the expected trace.
Check your work
A 3-step trace showing Step 1 evaluates `isAvailable || borrowedCount < 3` as `false || true -> true`, isolating the `||` operator.
Quick check
This browser could not save your progress. Changes last until you leave the page.