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 Working with jQuery Collections The .each() method

Bret Lynn
Bret Lynn
7,037 Points

jQuery Error code but my code seems to work

I can't figger out what the problem is. I seem to have check boxes that work, but I can't get rid of this error code.

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <h2>My Favorite Things</h2>

    <ul class="favorite-things">
        <li>Kittens</li>
        <li>Rainbows</li>
        <li>Unicorns</li>
        <li>Sprinkles</li>
    </ul>

    <script
    src="jquery-3.2.1.min.js"></script>
    <script src="app.js"></script>
</body>
</html>
app.js
$('.favorite-things li').each(function() {
  const checkBox = '<input type="checkbox"/>';
  $(this).prepend(`${checkBox}`);
});

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You've done something that is functional but isn't quite what the challenge is expecting. You created a variable and then used the value of the variable in your prepend method. When I do the same thing directly (without making the variable), your code passes!

 $(this).prepend('<input type="checkbox"/>');

:bulb: Going forward, note that it's always a good idea to not do anything not explicitly asked for by the challenge. Even if functional, it can cause the challenge to fail.

Hope this helps! :sparkles: