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 trialguram dgebuadze
Front End Web Development Techdegree Student 4,122 PointsOne line arrow function why can't I write this arrow function on one line? without curly braces
const myHeading = document.getElementById('myHeading');
myHeading.addEventListener( 'click', () => { myHeading.style.color = 'red'; });
2 Answers
Elijah Quesada
Front End Web Development Techdegree Graduate 32,965 PointsIt is possible. You would need to remove the curly braces as mention as well as the first semi-colon after "red". Currently when the JS engine reads this statement it ends before that closing parenthesis for the event listener. If you look in your console.log you will see the error "missing ) after argument list" since the statement ended before the closing parenthesis.
myHeading.addEventListener( 'click', () => myHeading.style.color = 'red' );
guram dgebuadze
Front End Web Development Techdegree Student 4,122 PointsThanks I had silly mistake and that's why this wasn't workink