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 (2014) Introduction to jQuery Include jQuery in a Project

ReferenceError: Can't find variable: $

I've included jQuery with the CDN link...

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

...but I keeping getting the Reference Error: Can't find variable: $. I've checked the code and it runs fine...?

4 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

We hit a little snag yesterday with our CC engine. It's fixed now. Sorry for the inconvenience.

Paul Carter
Paul Carter
12,543 Points

You da best Andrew, thanks.

Thanks Andrew. It's all good now.

Calvin Nix
Calvin Nix
43,828 Points

Hey Michael,

Please remember to format the code that you write in the forums so that it is easier to read. I went ahead and formatted your existing code for you.

Concerning your issue,

This may be a bug in the code challenge. Unless I am not remembering correctly, the code challenge below should work (but for some reason it doesn't). The error message indicates that JQuery isn't being loaded properly because JavaScript alone has no idea what $ is.

<!DOCTYPE html>
<html>
<head>
    <title>Take Evasive Action</title>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
    <p class="warning">
      <span>It's A Trap!</span>
    </p>
    <div class="image">
        <img src="img/ackbar.gif">
    </div>

  <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <script src="js/app.js" type="text/javascript" charset="utf-8"></script>


</body>
</html>

Andrew could you please look into this?

thanks,

Laura Cressman
Laura Cressman
12,548 Points

The bug is you need to go into the app.js file and delete the code that's there. I had the same issue yesterday, but made the app.js file blank and it worked for me :)

Calvin Nix
Calvin Nix
43,828 Points

Hi Laura,

The "bug" in this case is most likely JQuery not being loaded.

Deleting the code in the app.js file most likely worked for you because the challenge probably hinges on whether or not that app.js file throws an error. Since this file contains JQuery, and JQuery isn't properly being loaded, the file throws an error and the challenge fails.

I would bet that you could properly add some basic Javascript in that file and it would pass as well.

Laura Cressman
Laura Cressman
12,548 Points

OK, that makes sense. I was just going for whatever got me to the next lesson haha :P

Calvin Nix
Calvin Nix
43,828 Points

Great resourcefulness :)

Paul Carter
Paul Carter
12,543 Points

Hi, I found my way here because I'm having the same issue. Deleting all the code from app.js let me pass the challenge but I imagine someone will want to fix this one.

Thanks peeps!