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 trialshyarkhalil
Front End Web Development Techdegree Graduate 17,762 PointsCould some one explain for me why ?
Why Gail use this statement if(index === indexToChange)
? So if index value is the same value of indexTochange then what is the logic to compare two things are the same?
1 Answer
Calin Bogdan
14,921 PointsHello!
Guil is actually iterating through all indexes and is changing only the selected index, indexToChange. That's why he's comparing the two, they're not identical.
Let's say he wanted to change the item at index 5. He's iterating through all items' indexes and checks whether the iterated index equals 5. If it doesn't, he will keep looking for the next item. On the other hand, if the index equals 5, he will perform the operation.
Hope it helped!