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 jQuery Basics Understanding jQuery Events and DOM Traversal DOM Traversal with jQuery

What's wrong with my code, it performs as intended?

I swear this test environment is full of bugs...It only want's code done only one way otherwise it will consider your code incorrect. Not very useful then since code can be written in many different ways and still produce valid outcome.

In this test, I am to select all of the ul element for '.student.list' and then using traversal, select only the li instance containing "Wade Christensen". My code does that and to prove it, I had my code change only the li element containing "Wade Christensen" and set its font color to green. This works, so what is the test's problem? How am I to learn if it always considers everything I do as being wrong despite whether it is actually wrong?

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
  <h2>Student List</h2>

  <ul class="student-list">
    <li>James McAvoy</li>
    <li>Alena Holligan</li>
    <li>Wade Christensen</li>
    <li>Matt Krzyzynski</li>
  </ul>

  <script src="jquery-3.2.1.min.js"></script>
  <script src="app.js"></script>
</body>
</html>
app.js
$(".student-list li").eq(2).css({color: 'green'});
Antonio De Rose
Antonio De Rose
20,885 Points

could you please post your answer, to the challenge 1 and 2

1 Answer

f lsze
f lsze
8,021 Points

I hear you. You're not really doing anything wrong. It's just that when they say:

select all of the list items on the page.

They literally want you to select all the list items on the page. So the correct answer would involve selecting $("li") and then doing the traversal. The difference is your code limits it to list elements within ul.student-list which is super subtle and I could definitely see why you would get frustrated. It would only actually make a difference if there were other unordered lists on the page.