Why won’t the score change when the ball reaches the end? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why won’t the score change when the ball reaches the end?

https://code.sololearn.com/WVZ7Xzvx5qCW/?ref=app I have an If and statement in the method scoreChange that should add one to the player score when the ball reaches canvas.width, but for some reason this doesn’t happen. The ball just keeps going and the score doesn’t change and I can’t figure out why. If someone has any insight or a solution to share as to why this happening and how it can be fixed that would be greatly appreciated.

9th Jan 2019, 6:54 AM
Thomas Czernek
Thomas Czernek - avatar
1 Answer
+ 6
It works if you put the collision detection in the ball class. But there are other problems like humanScore seems to be a constant etc. ballMotion(){ this.ballXPos = this.ballXPos + 1; if(this.ballXPos == canvas.width){ console.log('collision'); //++humanScore; } else if(this.ballXPos == 0){ //++computerScore; } }
9th Jan 2019, 8:14 AM
Anna
Anna - avatar