I made some code that wouldn’t work. An error popped up in the Chrome console saying “Syntax error: Unexpected identifier”. Error is on line 19. Here is the code:
JavaScript
x
14
14
1
13. var canvas=document.getElementById("canvas")
2
14. var ctx=canvas.getContext("2d")
3
15. function getMousePos(canvas,evt){
4
16. var rect=canvas.getBindingClientRect()
5
17. return{
6
18. x:evt.clientX-rect.left
7
19. y:evt.clientY-rect.top
8
20. }
9
21. }
10
22. canvas.addEventListener("mouseclick",function(evt){
11
23. var mousePos=getMousePos(canvas,evt)
12
24. ctx.fillRect(mousePos.x-15,mousePos.y-15,10,10)
13
25. },false)
14
Advertisement
Answer
from line 17: add a comma on line 18 as @thg435 mentioned
JavaScript
1
5
1
return {
2
x:evt.clientX-rect.left,
3
y:evt.clientY-rect.top
4
}
5