Fix Exercise 3.4 solution to count consecutive wrong passwords#1192
Conversation
Exercise 3.4 calls the cops after seven *consecutive* accesses with an incorrect password, but the solution counted total failed attempts and never reset. Reset invalid_attempts to 0 on a correct password. The existing example (eight consecutive wrong attempts) still escalates to call_the_cops, so the snippet's EXPECTED value is unchanged. Reported by GitHub user KrNor in #1138. Closes #1138 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request adds a reset for invalid_attempts to 0 upon a correct password entry in the dispatch function. However, a logic bug was identified where a user is locked out on their 8th attempt even if they enter the correct password, because the check invalid_attempts < 7 prevents the password from being verified once the limit is reached. A restructuring of the function is suggested to resolve this issue.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Fixes a logic error in the Exercise 3.4 solution (
xml/chapter3/section1/subsection1.xml), reported by GitHub user KrNor in #1138.Problem
Exercise 3.4 asks to call
call_the_copsafter seven consecutive accesses with an incorrect password. The solution counted total failed attempts and never reset, so a correct access in between still accumulated toward the limit.Fix
Reset the counter on a correct password:
Checks (simulated in Node)
call_the_cops, so the snippet's<EXPECTED>value is unchanged.Note: the issue also suggested adding a commented-out successful request to the example. I left the example as-is — it's a hidden test snippet with an
<EXPECTED>value, so a commented line wouldn't be visible to readers and would break<EXPECTED>if uncommented. Happy to add a proper reset-demonstrating example if you'd prefer.Closes #1138