I’d really appreciate if someone could kindly answer to my questions about JavaScript objects (evil circle) test.
Thank you in advance!
Question 1.
For collision detect of evil circle, I originally wrote ball.exists === false but then the count kept declining. Why should this be = instead of ===?
Question 2.
To update the ball count, is there any way I don’t have to re-write "Ball count: " but somehow use the text already written in <p> in HTML?
Question 3.
I originally set the x and y of evil circle as below, but that way, nothing was displayed on screen. Why doesn’t this work? const evilCircle = new EvilCircle( random(0 + size, width - size), random(0 + size, height - size) );
We don’t want to compare the values, we want to assignfalse to ball.exists. The reason is that when the condition (distance < this.size + ball.size) is met, we have a collision and want to remove the ball. Therefor we set its exists property to false.
I think it’s a good idea to change the whole text like you did. That makes it easy an clean and we are not talking about replacing millions of characters.
If you absolutely want to, you could have a span inside the para and only change its content:
When you encounter such errors I recommend looking at the console. There we see: “ReferenceError: size is not defined”. There reason is that the size variable is defined inside the EvilCircle class and is unknown to the global code that creates the evil circle.