JavaScript jQuery Basics Working with jQuery Collections Working with jQuery-Specific Selectors

Jiten Mehta
Jiten Mehta
Front End Web Development Techdegree Student 7,929 Points

Can't pass this code challenge...

Hi guys, I can't seem to pass this code challenge.

The challenge is asking me to show the hidden li elements using Jquery.

This is the code i used.

const $Picard = $('li:hidden');

$Picard.show();

It shows in the preview but I am not passing the challenge. Any ideas?

Thanks, Jiten.

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
    <h2>Star Trek Characters</h2>

    <ul class="character-list">
        <li>Captain Jean Luc Picard</li>
        <li>Data</li>
        <li>Worf</li>
        <li>Dr. Crusher</li>
    </ul>

    <div>I am supposed to stay hidden!</div>    

    <script
    src="jquery-3.2.1.min.js"></script>
    <script src="app.js"></script>
</body>
</html>
app.js
const $Picard = $('li:hidden');

$div.show();

3 Answers

Steven Parker
Steven Parker
173,537 Points

The variable names don't match in the inset code sample ("$Picard" vs. "$div"), but I think the more important issue is that the challenge doesn't really want you to create an intermediate variable (even though it would work in practice).

Try applying the "show" method directly to the jQuery object created with the selector.

Jiten Mehta
Jiten Mehta
Front End Web Development Techdegree Student 7,929 Points

Hi Steve, thanks for this. The variable names did not match because I was experimenting at the time I posted this question, that was my mistake.

You were right, I did not need to create a variable.

The following worked,

$(li:hidden).show();

As someone who is used to working with HTML and CSS, Javascript is very difficult to get my head around.

Thanks again, Jiten.

Steven Parker
Steven Parker
173,537 Points

jQuery can sometimes seem like another language of its own!

Joseph Cowan
Joseph Cowan
3,941 Points

Oh this helped. I have a thing for turning things into variables and didn't realize they weren't asking for that. Thanks for this!