Using API for the Random Quote Machine Challenge

I am not sure how to use API with JSON. I’ve looked back at the previous exercises and I am still kind of lost.

I understand how to use the “on click” event function, I am pretty sure I know how to declare a string var and just += to it. I also found a free quote API, but I have no idea how to access it.

The API I Googled is here:

My Codepen is here:

Any help will be appreciated.

1 Like

Hello – you can also generate your own quote object directly in your app, and randomly access quotes from there, if you want to build something you’re more personally invested in and avoid the hassle of dealing with an API (until the weather app :slight_smile:).

Otherwise you could use the jQuery ajax method. So onclick, you’d run the ajax method that takes your API url as an arg, and display something based on success or failure of that request.

1 Like

Hi, You need to add the jQuery javascript file (Settings/Javascript).
Also, your the JS pane in your pen is empty.

Here’s another random quote generator.

btw I am also struggling to get getJSON to work for me :confounded:

Cheers, Rainer


Apologies, my bad. I meant to paste in this https generator:
Thank you for the advice.

Is there any API which also returns image url?

Yea, actually there is.

thanks - that link works out of box :slight_smile:

1 Like