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 trialjne
12,613 PointsIs listitem set to list items on the page or the variable listitems??
On this challange there is a var anchor = listitem; and a var listitems = navigation. Is listitem bound to a random listItem on the page or is there a bug here. I would think that var anchor = listitem, would be var anchor = listItems. Because listitems(listitem) points to the variable listitems.
Am I right here?
If you see the code look for line 5 and 14.
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsAfter the correction to line 5, listItems
is a collection of all the list items within the navigation.
listItem
is one of those list items.
I think the key piece of code which connects these two is the for
loop.
It's looping through all the listItems
and passing each individual list item into the bindEventsToLinks
function.
Then, after the correction to line 14, you're getting the anchor element that belongs to the particular listItem
that was passed in.
jne
12,613 PointsThank you! I understand it now!
Andrew Shook
31,709 PointsPart 2 of the code challenge ask you to change line 14 so that var anchor = the link inside of each individual listitem.
jne
12,613 PointsLook at this picture: http://imgur.com/Px3Izpc
What I'm asking is if the "listitem" on line 14 has any relationship to the variable "listitems" on line 5. I would think they would have a relationship, because variable anchor is suppose to target anchor elements inside the list items, and list items is given by the var "listItems". But "listitems"(line 5) is not equal to "listItem" on,one 14, there seems to be missing a "s".
If I'm incorrect here. How will the variable anchor be targeting specific listitems, will it take every listitem it finds? I know how to pass this test, so I know the answer, but I don't see the logic here.
Andrew Shook
31,709 PointsLook at line 19. The for loop there, loops over the array listItems. Each time the loop executes, it calls the function bindEventsToLinks that is declared on line line 12. On line 20, you can see that each time the for loop runs it passes a single item from listItems into the bindEventsToLinks(). On line 12, in the function definition, you can see that anything passes to the function is called listItem inside the function definition.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Joakim,
This code challenge asks you to change both lines 5 and 14.
Are you asking this question in the context of the starter code or do you think there's a bug even after the 2 changes?