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

Daniel McHugh
Daniel McHugh
1,821 Points

Arrow syntax not working?

This code from the video is not working when I use arrow syntax to replace the function. What am I doing wrong? Here's the screenshot: https://w.trhou.se/jqd9s1k8rw It works perfectly when I replace it with a normal function.

We can't see your code.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Thanks for including the link to your workspace so that we can see your code. I'm a bit curious as to what browser and what version of the browser you're using. When I fork your workspace and replace the normal function with an arrow syntax function, it works for me. So I'm wondering if it's supported in your browser.

That being said, it would be nice if you had left the arrow syntax that you tried in instead of the function that does actually work so that we can rule out errors there. :sparkles:

Daniel McHugh
Daniel McHugh
1,821 Points

Here is an updated screenshot: https://w.trhou.se/ek2eiidvkn

and here is the code: const myHeading = document.getElementById("myHeading"); const myButton = document.getElementById("myButton"); const myTextInput = document.getElementById("myTextInput");

myButton.addEventListener("click", () => { myHeading.style.color = 'red'; });

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again, Daniel! I just forked the new one and there's good news and bad news. The good news is that it works on my end.! I click the button and the headline changes to red. But the bad news is that I still don't know why you're not seeing what I'm seeing. So once again, what browser are you using and what version? Because it may very well be that you're using a browser where arrow syntax simply isn't supported.

As Jennifer said, it works correctly for me too, I am using the latest Google Chrome. Cheers.

Daniel McHugh
Daniel McHugh
1,821 Points

Okay, thanks everyone. I'm at work using IE 11 since it's the only browser available. I'll just write it out the long way while I'm using this browser.

1 Answer

Steven Parker
Steven Parker
231,248 Points

The browser is the issue. According to Can I Use?, IE 11 does not support arrow functions.