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) Making Changes to the DOM Getting and Setting Text with textContent and innerHTML

Rod R
Rod R
3,050 Points

step 1 in demo causes error- Uncaught SyntaxError: Identifier 'myHeading' has already been declared at <anonymous>1:1

I launched the workspace for this video and the first step is causing a console error. Guil is entering > let myHeading = document.querySelector('h1'); But when I do the same I get a console error: Uncaught Syntax: Identifier 'myHeading' has already been declared at <anonymous>:1:1 Can I clear it somehow? Here is the default HTML in the workspace:

<!DOCTYPE html> <html> <head> <title>JavaScript and the DOM</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <h1 id="myHeading">JavaScript and the DOM</h1> <p>Making a web page interactive</p>
<p>Things that are purple:</p>

<ul>
  <li>grapes</li>
  <li>amethyst</li>
  <li>lavender</li>
  <li>plums</li>
</ul>
<script src="app.js"></script>

</body> </html>

I launched the webpage, opened the console, and typed:

let myHeading = document.querySelector('h1');

How can I get past this error to code along with Guil?

Steven Parker
Steven Parker
231,270 Points

This is a JavaScript issue, yet it looks like you've only shared the HTML file. But you can share the entire workspace easily by using the "snapshot" function (the camera icon) and then posting the link it gives you.

1 Answer

Steven Parker
Steven Parker
231,270 Points

The app.js file that your HTML loads currently contains just one line: "var myHeading;" So it is indeed already declared.

You could either remove that line from the file, or when you enter your console code, just omit the keyword "let".