Random Quote Machine codepen problem

Hello! I have a skeleton for a random quote machine (sans css and tweet function) on
https://codepen.io/rhuss623/pen/deEyLo
I took the javascript and put it into the html portion of codepen so I could copy and paste it into a freecodecamp phone screen module, such as the JSON API’s and AJAX challenges. It works when copied and pasted into a freecodecamp editor, but it doesn’t work in codepen. Any ideas? Any help is hugely appreciated!

The link doesn’t work.

SpaniardDev you are awesome! Thanks for helping!!!

Does the link work, now?

Yep.

Ok. First of all, the body tag can never be surrounded by any elements other than the HTML tags. The divs must be inside the body. In fact, when coding HTML in Codepen you can omit the use of the body element as it is included by default by the text editor.

That being said, you need to import the library into your document, otherwise it won’t recognize your code as standard Javascript. You can do this by importing it directly into your HTML code, like this:

<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>

Or you can use Codepen’s setting to import it. The latter method will require you to move your Javascript code into the editor labeled Javascript, so it can make use of jQuery.

Hope it helps.

Thanks!

I’ve removed the body tags and included the library that you’ve supplied. Unfortunately, it still neither works when in the HTML editor w/ the jquery library added nor in the Javascript editor (without the script tags).

I see the same code at Codepen. Please, update the code. I want to make sure you did it right.

Forgot to save changes!

Here’s the updated first one, again: https://codepen.io/rhuss623/pen/deEyLo

Here’s a fork using the JS editor panel: https://codepen.io/rhuss623/pen/jxomWg

I ended up forking someone else’s project, deleting their code, and inserting my own (unchanged) code. That worked! I’m beyond confused, but thanks for the tips SpaniardDev and randelldawson!!!

How would you link jQuery to it? This sounds like something I’ll need to know in the future.

Thanks!!! And you’re totally right! The fork I copied my code into had already added JQuery

1 Like

Hey friends!

Here’s my first draft at a random quote generator using my own quotes:

Feedback appreciated!

And here’s a buggy first draft using an API:

Nothing happens when I hit the button and I’d love a little advice!

  1. I figured I’d made a silly mistake :wink:
    2)I hadn’t known how to check for errors in the browser console…that’s so useful!!

Merci beaucoup!!!

Updated code: https://codepen.io/rhuss623/pen/rvXmwa?editors=0010