This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Viktor Matusov
over 9 years

Why won't my "Drag Racing" codeacademy code work locally?

I have successfully completed “Drag Racing” exercise @codeacademy, but when I copied all the same code locally, the car appeared, but I couldn’t drag it. Please advise!

Answer 5490e80195e378bc1f000f0e

0 votes

Permalink

You need to link out to the jQuery core library. There are several CDN’s where it can be linked from. The following uses two of them, one for the core, one for UI

<script src="http://code.jquery.com/jquery-1.11.1.min.js"><script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>

Load these scripts (in this order) before your custom script so it is present when your script fires. Style sheets should be loaded before any scripts.

For running locally, do not use schemeless protocol ("//ajax. ...") or it will resolve to your computer’s file:// protocol, not http://

points
Submitted by Roy
over 9 years

5 comments

Viktor Matusov over 9 years

I knew it was about the scripts linking, but never realized the order mattered. Thanks!

Pieter over 9 years

first == core and second == UI ?? I want to put a comment.

Roy over 9 years

Script loads and parses in the order that the files are listed in the document, starting with the HEAD and then the BODY. Non-deferred script fires as soon as it is parsed. I’m not sure that jQuery is defined in the UI, so it follows that library depends upon the jQuery core to define $ (jQuery). Likewise, if our own script makes calls to jQuery, it won’t exist if not already loaded. In general terms, order is implied when there are dependencies.

meerkat5 over 8 years

so, what do I put in? the file:// or the http://! Thanks anyway!

Roy over 8 years

http:// so it resolves to the web.

Answer 55b1424a937676502b000222

0 votes

Permalink

I have the same problem! I want to use it on my website, but, when I made sure it worked, the code was the same as codeacademy gave me, but it didn’t work! Thank you Roy, for helping me! ;)

points
Submitted by meerkat5
over 8 years