JavaScript JavaScript and the DOM Responding to User Interaction Listening for Events with addEventListener()

1 Answer

Peter Vann
Peter Vann
36,049 Points

I hope I am understanding your question correctly. Did you mean: "Why is the textContent on both sides of the equals sign?"? After watching the video, I believe you are referencing this line of code:

listItems[i].textContent = listItems[i].textContent.toUpperCase()

This function:

listItems[i].textContent.toUpperCase()

Only RETURNS the uppercase value of whatever listItems[i].textContent happens to be on that iteration. This alone:

listItems[i].textContent.toUpperCase()

does not change listItems[i].textContent itself. The only way to achieve a persisting modification of the listItems[i].textContent text is to reassign the modified textContent back to itself, which is what this line of code it doing:

listItems[i].textContent = listItems[i].textContent.toUpperCase()

Is that what you meant? Anyway, I hope that helps. Happy coding!