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 trialGrant Evans
3,259 PointsIdentifier 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
KRIS NIKOLAISEN
54,971 PointsMore 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
3,259 PointsThanks very much!