Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,627 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: