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 trialSean Fallon
8,516 PointsWhy use i += 1 and not i++?
When he loops through list items to capitalize them on hover, he uses i += I thought 1 += 1 will give you 11. So that wouldn't loop through all the <li>
Here is the teachers example.
for(i=0; i<listItems.length; i+=1) {
listItems[i].addEventListener('mouseover', () => {
listItems[i].textContent = listItems[i].textContent.toUpperCase();
});
listItems.addEventListener('mouseout', () => {
listItems[i].textContent = listItems[i].textContent.toLowerCase();
});
};
1 Answer
Mark Casavantes
2,880 PointsHello Sean,
I think i++ is the same as i+=1 . listItems.length = 9 so then i+= would be 10.