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 trialKevin Sweet
8,081 PointsStart button display
Hello,
I have an issue with the start button display not changing to 'none' when using 'this' to address it in the event listener. When I change it to use document.getElementById("begin-game") it works as expected. When it is this.style.display = "none" I get a TypeError:
Uncaught TypeError: Cannot set property 'display' of undefined at HTMLButtonElement.<anonymous> (app.js:8) (anonymous) @ app.js:8
Any thoughts?
1 Answer
Steven Parker
231,248 PointsDid you set up your handler using a arrow function (with a "=>")? Arrow functions don't define "this" like conventional functions do.
If that's not it, please show your code so we can give you a specific answer.
Kevin Sweet
8,081 PointsI did indeed use an arrow function. Is there a different way to use this with arrow functions?
Steven Parker
231,248 PointsYes, you can establish a parameter to receive the event object, and use the "target" attribute on it instead of "this".
KRIS NIKOLAISEN
54,971 PointsKRIS NIKOLAISEN
54,971 PointsCan you post a snapshot? Click the camera icon in the upper right corner, then 'Take Snapshot', then post the link created here. If you aren't using a workspace you can easily create one by dragging your files to the lower left corner of a new workspace.