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 trialAvaya AD Team
18,899 PointsArrow function not working
Anyone would know why if i use an arrow function instead of an anonymous function declaration, the callback inside de eventlistener will not run? See below for code:
//this works
document.getElementById("begin-game").addEventListener('click', function() {
game.startGame();
this.style.display = 'none';
document.getElementById('play-area').style.opacity = '1';
});
//this doesn't
document.getElementById("begin-game").addEventListener('click',() => { game.startGame(); this.style.display = 'none'; document.getElementById('play-area').style.opacity = '1'; });
1 Answer
Marquise foster
5,336 Pointssame thing happened to me ! think it doesn't want us to use arrow functions for some reason.