https://github.com/Dzhango/bouncing-balls.git
I have completed everything except for the ball counter.
If you could please give me a hint on how to address the counter. I am getting either a zero when I initialize ballcount variable, or I get a lot of different random numbers.
Also, question: does having class based structure allows me to neglect the prototypes, since Shape is the Parent class, so I simple call super in EvilCircle and Ball.
Thank you!
first, congrats for your first post and welcome to the community.
about the counter,
you initilized it with 0 as expected.
but you should move the ballNum += 1
and ballNum -= 1
to more appropriate places:
move the ballNum += 1
to the place in the code where you create a ball
move the ballNum -= 1
to the place in the code where you remove a ball
also don’t forget to actually update the counter’s dom element when you update the counter’s value (for example like this: counter.textContent = `Ball Count: ${ballNum}`;
).
also, change this line: if(this.exists)
to if(balls[j].exists) {
in this case, the this
is the evil ball which always exists. you want to check if the other ball exists
In addition, when drawing the evil circle you want to use ctx.stroke();
and not ctx.fill();
about your second question, when you use the class syntax you don’t have to deal with prototypes (it will be automatically managed for you)
if you have more questions or still struggling with the exercise feel free to ask for more help
It works! Thank you, so much!