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 trialNikolay Komolov
23,033 PointsUncaught error on moving a mouse: Cannot read property 'offsetX' of undefined
Hello! Could you help to understand, please?
If I comment the 'mouseDown' condition, when I move a mouse on the canvas, the console prints out a bunch of errors: Cannot read property 'offsetX' of undefined (where undefined should be the 'lastEvent' variable on line 59). Here is my workspace:
I would like to understand why it happens. Thanks :)
1 Answer
akak
29,446 PointsThat's because lastEvent is undefined.
var lastEvent;
console.log(lastEvent); //prints out undefined
when you define variable like that it's value is undefined until you assign something to it. If you comment out mousedown, there is nothing that writes any value to it so it stays undefined. :)
Nikolay Komolov
23,033 PointsNikolay Komolov
23,033 PointsOh, I see. Thanks!)