Assessment wanted for Adding bouncing balls features - checkBounds()

Hi,
In my bouncing balls assignment my, evil circle keeps going out of the window; the checkBounds() function doesn’t seem to work

Link to code (codepen.io): https://codepen.io/Kaustubh-Maladkar/pen/gOvGROa
Link to assignment: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Adding_bouncing_balls_features

Hi @kaustubhmaladkar and welcome to the community :wave:

I recommend adding/subtracting this.size when you meet the conditions. This will just move the circle slightly back into the canvas.
For example the first line could be

if ((this.x + this.size) >= width) this.x -= this.size;

Also, pay attention to correctly use this.x and this.y depending on horizontal or vertical conditions.

I hope that gets you further in the exercise. :slightly_smiling_face:

Have a nice day,
Michael

PS: Your email address is visible in your post. I think it somehow ended up in the optional “name” field of your profile. I recommend removing it.

1 Like

Thanks a lot. Your solution seems to work

1 Like