Using API for the Random Quote Machine Challenge

Using API for the Random Quote Machine Challenge
0

#1

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: https://forismatic.com/en/api/

My Codepen is here: https://codepen.io/mattr8/full/qjxKQR/

Any help will be appreciated.


#2

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.


#4

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. https://random-quote-generator.herokuapp.com/api/quotes/

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

Cheers, Rainer


#6

Apologies, my bad. I meant to paste in this https generator:
https://random-quote-generator.herokuapp.com/api/quotes/
Thank you for the advice.


#7

Is there any API which also returns image url?


#8

Yea, actually there is.
https://source.unsplash.com/


#9

thanks - that link works out of box :slight_smile:


#12