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

Grant Evans
Grant Evans
1,793 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

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,735 Points

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
1,793 Points

Thanks very much!