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 JavaScript and the DOM (Retiring) Getting a Handle on the DOM A Simple Example

Fredrik Johansson
seal-mask
.a{fill-rule:evenodd;}techdegree
Fredrik Johansson
Full Stack JavaScript Techdegree Student 12,390 Points

Sharing my solution/code

//Declaring an arrow function which styles the ID "myHeading" with a red color. Putting the function in a const variable named changeColor. Since the function doesn't have any parameters I need to use parenthesis. And since there's not a multi-line I can build everything in one line.

const changeColor = () => {document.getElementById('myHeading').style.color = 'red';}


//Calling the function once the ID "myHeading" is clicked.

document.getElementById('myHeading').addEventListener('click', changeColor);

2 Answers

Looking great but because you don't have any parameters doesn't mean you should use the arrow function. You also don't need curly braces.

https://medium.freecodecamp.org/when-and-why-you-should-use-es6-arrow-functions-and-when-you-shouldnt-3d851d7f0b26#c6ea

This is a good read.