Skip to main content
This lesson walks through diagnosing and fixing issue #1 in the BlockBuster repository: exponential growth of balls when the multiBall power-up is applied. It includes the root cause analysis, a safe fix, and the Git workflow for fetching, checking out, committing, and pushing the change. Repository / user context
  • Repo: BlockBuster
  • User: GH900
  • Issue: #1 — exponential ball growth caused by the multiBall power-up
Problem summary The multiBall handler duplicates all current balls by iterating gameState.balls and pushing clones into the same array. Because the code mutates the array while iterating it, newly pushed balls are also iterated, causing exponential growth on repeated activation. Reproduction (relevant snippet)
Root cause
  • Mutating (pushing into) an array while iterating it with forEach causes the loop to process elements added during iteration.
  • The guard if (gameState.balls.length < 5) only checks at the start; pushing inside the loop invalidates the assumption and allows the array to grow beyond intended limits.
Best practice note
When modifying arrays you are iterating over, iterate over a shallow copy (for example, arr.slice()) or use an index-based loop that references the original length. Always enforce an explicit maximum when duplicating entities to prevent runaway growth.
Safe fix
  • Iterate over a copy of the original balls so newly added balls are not reprocessed.
  • Apply a strict upper bound (MAX_BALLS) to stop duplication once reached.
Corrected implementation:
This ensures:
  • Only balls that existed at activation are duplicated.
  • The total number of balls never exceeds MAX_BALLS.
Working with the issue branch (Git workflow) Fetch the remote branch, inspect it locally, check it out to track the remote, apply the fix, test, then commit and push.
  1. Fetch remote branches
  1. List local and remote branches
  1. Check out the remote issue branch and set it to track origin
Make the change and test locally
  • Open script.js, apply the corrected code above (or an equivalent safe approach).
  • Run the application locally to confirm the fix and check for regressions.
Example local test command:
Commit and push the fix
  • Reference the issue number in the commit message so GitHub links the commit to the issue (e.g., refs #1 or #1).
Sample push output:
On GitHub
  • After pushing, refresh the repo page. The commit will appear on the remote branch and GitHub will auto-link the commit to issue #1 if the commit message includes the issue reference.
  • From there, open a pull request to start code review and CI checks.
Common Git commands used in this workflow Next steps
  • Open a pull request from the branch and continue with code review and CI.
  • Consider adding a unit or integration test that validates the multiBall behavior to prevent regressions (for example, assert the ball count never exceeds MAX_BALLS after activation).
Links and references

Watch Video