This is probably something very simple and stupid, but why doesn't it return anything? I have this simple class method:
checkCollision(event) { let eventX = event.clientX - canvasRect.left; let eventY = event.clientY - canvasRect.top; if (this.centerX - eventX <= this.radiusX && this.centerX - eventX >= (this.radiusX/-1) && this.centerY - eventY <= this.radiusY && this.centerY - eventY >= (this.radiusY/-1)) { console.log(true); return true; } else { console.log(false); return false; } }
But when running in the browser, its output is
> obj.checkCollision({clientX: 200, clientY: 200}) false <- undefined
Why doesn't it return anything? console.log is running but no return value
I added some arbitrary values to the variables you used, but I was able to get your code to work like this:
Also, a little tip. When you explicitly return
true
orfalse
based on a Boolean expression, you can also directly return the Boolean expression itself.