Assessment wanted for Adding bouncing balls features

Link to task https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Adding_bouncing_balls_features

I’m not sure if it’s OK to ask for an assessment in this case.

I completed the original assessment and it was pretty close to the way MDN did it.

While doing the assesment I had some ideas to try, so I redid it.

This time I eliminated the exist and evilCircle collisionDetect().

I also added a bunch of new features.

Finally I changed a bunch of code to comply with airBnb linter rules.

All this led to a lot more learning which is good, but I am wondering if I am going on the right path with the code, or am I messing up?

If I should not be asking for an assessment with all these changes, I understand and wouldn’t do in the future.

Thank You.

My code is at https://codepen.io/gcaine/pen/ExjgrpO

Hi there @garcai, and thanks for sharing your code!

Your additions look pretty good to me; I think it is great that you making your own thing from my example!

I don’t really have time to go through and assess all your additions in detail, but this doesn’t mean you shouldn’t send me your code — I am always happy to see what people have created with the help of my courses. If there were a couple of specific items you wanted feedback on, I could maybe help you with those.

OK in another thread you said

The logic is a little odd here; I could probably have come up with a more elegant solution here, but I remember finding it difficult to come up with something that worked, quickly :wink: The problem was around the fact that array items don’t have a specific index to identify them, and it is not easy to just delete one anywhere in the array. There is probably a better way.

What i did was move the evil circle collision detection to the bouncing balls and remove the ball from the array as below.

It ‘seems’ to work, but is there a case that it could be a problem?

Ball.prototype.collisionDetect = function collisionDetect() {
// eviCircle collisionDetection
let dx = this.x - evilCircle.x;
let dy = this.y - evilCircle.y;
let distance = Math.sqrt(dx * dx + dy * dy);

if (distance < this.size + evilCircle.size) {
const index = balls.indexOf(this);
balls.splice(index, 1);
ballCount -= 1;
ballsHit = startBallCount - ballCount;
}

// balls collisionDetection