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 trial

JavaScript One Solution

Begana Choi
PLUS
Begana Choi
Courses Plus Student 13,126 Points

I have a question about #4

in this video,

// 4: Using traversal, store the second-to-last list item in a variable named prevItem

const prevItem = lastItem.previousElementSibling; prevItem.style.backgroundColor = '#f36f49';

it used this code but in my mind, the previous element sibling of the last item is third item, not a second item. and not a second-to-last list item, only the third item. why it's like this? please let me understand this. thank you so much for everybody!!

2 Answers

Steven Parker
Steven Parker
231,269 Points

The comment doesn't say "second item" , it says "second-to-last". The term "second-to-last" means "the item just before the last", which is what this code is referencing.

If there are four items, the third item is also the "second-to-last" one.

Begana Choi
PLUS
Begana Choi
Courses Plus Student 13,126 Points

thank you. then it was just my lack of language problem! thank you so much.