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 trialGavin Eyquem
Front End Web Development Techdegree Student 21,339 PointsGoing wrong somewhere with the .prev() method in jQuery.
This is the code I am using for the 2nd objective - $('li').eq(2).prev();
What am I doing wrong?
Help is welcomed.
<!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>
$("li").eq(2).prev();
2 Answers
Steven Parker
231,275 PointsThe instructions ask you to "traverse from Wade Christensen to James McAvoy in the list of students."
But James McAvoy is not the student immediately previous to Wade Christensen, so using "prev()" just one time will return a different student.
Jeremy Freedman
2,955 PointsI used TWO prev() methods and the quiz still screwed me
Gavin Eyquem
Front End Web Development Techdegree Student 21,339 PointsGavin Eyquem
Front End Web Development Techdegree Student 21,339 PointsHey Steven, I corrected my mistake.
My mistake was not using an additional .prev() method.
Thanks for your reply.
Steven Parker
231,275 PointsSteven Parker
231,275 PointsGavin Eyquem — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!