Random Quote Machine - my code isn't working

Hi everyone,
I’m doing the Random Quote Machine projects and to be honest I’m completely lost since I have only a very vague idea of how to go about it. I don’t want to peek at the code given in the example because I want to solve this myself, but since this is the first project I do with jQuery, I need some help!
Here’s what I did so far:

https://codepen.io/virginiab/pen/rvaYLv

and it isn’t working. Can someone point me in the right direction?
Thanks so much!

P.S.: ignore how ugly it looks, I just wanna get it to work before I add the CSS and the tweet button.

In the console it says $ is not defined so I guess you didn’t import JQUERY. In addition, after that you will get a cross origin error. Do you want to tackle that or do you want a solution?

I just added this:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

to my html head element because silly me, I forgot to do that, but it still isn’t working.
Now I’m getting this error:

Failed to load https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&jsonp=parseQuote&lang=en: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://s.codepen.io’ is therefore not allowed access.

Read the rest of my reply

Oh right, sorry. Do you have any resources where I can read about this issue and how to solve it myself?

You basically have it solved it’s just a silly mistake. Has to do with parseQuote in your url

Aww man, major facepalm :joy:
fixed it:
var url = "https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&jsonp=?&lang=en";

Thank you so much!!

1 Like