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 trialmark pollard
6,079 Pointschallenge says lists items is wrong to make it the children of the navigation ul. tried everything just learned
any help
//Select the naviagation
var navigation = document.getElementById("navigation");
//Select all listItems from the navigation
if(navigation.children.length) {
var children = navigation.children;
for (var i = 0; i < children.length; i++)
)
//When a navigation link is pressed
var linkListener = function() {
console.log("Listener is clicked!");
}
var bindEventsToLinks = function(listItem) {
//Select the anchor
var anchor = listItem;
//Bind the linkListener to the anchor element (a)
anchor.onclick = linkListener;
}
for(var i = 0; i < listItems.length ; i++) {
bindEventsToLinks(listItems[i]);
}
<!DOCTYPE html>
<html>
<head></head>
<body>
<ul id="navigation">
<li>
<a href="#home">Home</a>
</li>
<li>
<a href="#about">About</a>
</li>
<li>
<a href="#contact">Contact</a>
</li>
</ul>
<p>A few of my favourite things:</p>
<ul>
<li>
Rain drops on roses
</li>
<li>
Whiskers on kittens
</li>
<li>
Brown paper packages wrapped up with string
</li>
</ul>
<script src="app.js"></script>
</body>
</html>
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Mark,
For Task 1, your line 5 is correct, but you added an if
statement and a for
loop that is not needed (or asked for by the challenge). var listItems = navigation.children;
selects the children as the challenge asked. If you restart the challenge to clear out the code, and just change line 5 to above, Task 1 will pass.
For Task 2, the challenge just wants you to use a method to select the a
elements in the unordered list. So line 14 should become var anchor = listItem.querySelector("a");
This part of the JavaScript course is kind of confusing as it covers much. I actually watched the videos a couple times, and I am still not fully comfortable. Just keep at it!
I hope this helped. Keep Coding! :)
mark pollard
6,079 Pointsthanks ill give it a try
mark pollard
6,079 Pointsmark pollard
6,079 Pointsvar listitems = navigation; was on line 5 when challenge began