Answer to Variables Lesson


I have spent two hours trying to put in the correct code for the third lesson in Introduction to Functions in the Jquery module to no avail.

Does anyone know the correct answer? Any help is appreciated in advance. Thanks!

The instruction prompt is:

"Check out the preview window. All looks well and good, except for #4—that's nonsense!

Create a variable called $target in script.js and use the = sign to assign it to the jQuery selector that represents #4 in the ordered list. When you run your code, it should fade away!

You're going to need your CSS knowledge for this one and there is more then one way to achieve this. Check the Hint if you need a reminder! "


The statement, "You're going to need your CSS knowledge for this one..." leads many people to think of a class or id attribute on the fourth OL LI element (the run that reads, "jQuery is for chumps!"). That is one approach but not uniquely CSS related.

In an earlier lesson we learned about pseudo-class selectors, (those that begin with :). We can put that lesson to good use in writing a traversal selector that finds the fourth element in the OL.

var $target = $('ol li:nth-child(4)');

We have assigned the jQuery object to the $target variable. That object is an element node, the fourth LI child of the OL.


Thank you! Thank you! Thank you!