mdn / content

The content behind MDN Web Docs
https://developer.mozilla.org
Other
9.22k stars 22.5k forks source link

Correcting the code in update and the collisionDetect functions #36869

Closed mukuld closed 2 days ago

Josh-Cena commented 2 days ago

None of these changes are actually necessary.

mukuld commented 2 days ago

Thanks for the feedback @Josh-Cena . However, if you look at the code closely there are two changes to the update function. One is of course the addition of Math.abs which may not be needed. The other change is the removal of -ve sign from the check for <= 0. If the -ve sign is left there, then the balls don't bounce of the left and top walls and they just go out of bounds.

See the difference here: Correct code: https://www.dharwadkar.com/NewSite/javascript/bballs.html Incorrect code: https://www.dharwadkar.com/NewSite/javascript/bballs-new.html

Josh-Cena commented 2 days ago

Both versions are working correctly and are both bouncing off all edges.

mukuld commented 2 days ago

Yes. I realized that. It was the Math.abs that was causing the issue with the -ve sign. Thanks for your review.

Best regards, Mukul Dharwadkar

Visit me at http://www.dharwadkar.com

On Tue, Nov 19, 2024 at 1:40 PM Joshua Chen @.***> wrote:

Both versions are working correctly and are both bouncing off all edges.

— Reply to this email directly, view it on GitHub https://github.com/mdn/content/pull/36869#issuecomment-2486807825, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGFROMUCSYG4GK3KU7AGZED2BOV5FAVCNFSM6AAAAABSDBGZTKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBWHAYDOOBSGU . You are receiving this because you authored the thread.Message ID: @.***>