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 trialSzabolcs Hetei-Bako
6,559 PointsI get this error in the console:
After typing in everything correctly I get this message.
[Error] SyntaxError: Can't create duplicate variable that shadows a global property: 'myHeading'
4 Answers
Nathan Gallagher
21,518 PointsThis is apparently a problem Safari has with declaring a let/const variable that shares the same name as a selected id attribute. I had some variables declared with const as you did and got the same error. Changed to let and still got it. Changed to var and it worked.
Szabolcs Hetei-Bako
6,559 PointsThanks Nathan :)
edinjusupovic
5,664 PointsThanks Nathan. I was experiencing the same issue on Safari. Anyone know why its not working even with let? strange error.
Szabolcs Hetei-Bako
6,559 Pointsconst myHeading = document.getElementById('myHeading');
const myButton = document.getElementById('myButton');
const myTextInput = document.getElementById('myTextInput');
myButton.addEventListener('click', () => {
myHeading.style.color = 'red';
});
Dennis Eitner
Full Stack JavaScript Techdegree Graduate 25,644 PointsSame here. But it only appears in safari not in chrome
Szabolcs Hetei-Bako
6,559 PointsI have this problem in Safari. With Chrome it is working.
Jeremy Hamilton
7,229 PointsI has to do with how the window element has attributes for each HTML ID. It's known, but faster just to change to var or change the name of the constant.
Ben Schroeder
22,818 PointsBen Schroeder
22,818 PointsCan you please copy and paste your script?