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

Jeremy Freedman
Jeremy Freedman
2,955 Points

This exercise is WRONG: https://teamtreehouse.com/library/jquery-basics-2/understanding-jquery-events-and-dom-traversal/

$('li').eq(2).prev().prev();

This is the correct answer

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
$('li').eq(2);
$('li').eq(2).prev().prev();

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

HI Jeremy Freedman

I'm not sure what you mean by "Incorrect"?

The answer to the challenge should only have one line of code. If you copy the two lines you have provided as the "correct answer" the challenge fails as it should because your code provided is in fact incorrect.

The first tasks asks you to select the list and the second task asks to transverse the list. This will all be done with one line of code, not two.

You should notice that just below the instructions for the tasks is an Important message regarding the challenge:

Important: In each task of this code challenge, the code you write should be added to the code from the previous task.

So, the second task is added onto the first task, so one line of code is correct, not two.

Hope that helps clear up why yours is actually not correct.

:) :dizzy: