Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Lucas Gallindo
Lucas Gallindo
1,781 Points

Working but I get Uncaught TypeError: Cannot read property 'offsetX' of undefined message

So guys, the simple drawing application is working fine, but I noticed that when I move the cursor into the canvas I get this error message on the console:

Uncaught TypeError: Cannot read property 'offsetX' of undefined

Is it OK? I mean, it makes sense, I am actually triggering the .mousemove event, but I just want to make sure if there isn't anything wrong.

Steven Parker
Steven Parker
229,644 Points

You should not see such an error. To facilitate analysis of your issue, please share your (markdown formatted) code here, or even better, make a snapshot of your workspace and post the link to it here.

A link to the course page in question would also be helpful.

Lucas Gallindo
Lucas Gallindo
1,781 Points

Sorry, first time I made a question here. Here is the Snapshot The course is this one: JQuery Basiscs Drawing application

It's about to be retired from tree house, but I didn't really like the course that is replacing it, so I watched it anyway.

1 Answer

Steven Parker
Steven Parker
229,644 Points

Try setting mouseDown initially to false.

On line 37, you initialize mouseDown to true, so when the cursor enters the canvas the handler will try to get the coordinates of the previous location which has not yet been saved.

You should initialize mouseDown to false instead.