Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) Getting a Handle on the DOM Selecting Elements with the Same Class Name

Grant Evans
Grant Evans
3,259 Points

Identifier already declared issue when running the 'for' loop with GetElementsbyTagName/ID

Hi Treehouse.

Opening up the workspace for "Selecting Elements with the Same Class Name" and trying log results to console (changing no code other than adding the console.log code) gives me the following error.

Uncaught SyntaxError: Identifier 'i' has already been declared

Is this an error that others have seen?

// Code Below const myLists = document.getElementsByTagName('li'); for (let i = 0, i < myLists.length; i += 1) { myLists[i].style.color = 'purple'; }

console.log(myList);

2 Answers

More than the console.log statement has been changed from the workspace code.

1) The workspace code uses const myList singular

2) There is a comma after let i = 0 instead of a semicolon. This is the cause of the error you see.

Grant Evans
Grant Evans
3,259 Points

Thanks very much!