I am absolutely Confused on the API Forismatics


so I am doing my random quote machine (which is not that good) and I started by setting up an array but then I came across the API forismatic site and decided that that would be a better option but have no clue where to start.Any help is appreciated thx .

this is my project (comments welcome):


Don’t get frustrated. APIs are very confusing. They are confusing enough, and every one is different and the documentation is often poor and they can change without you even knowing it.

var corsString = "https://cors-anywhere.herokuapp.com/";
var apiString = "api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json&json=?";

    url: corsString + apiString,
  .done(function(data) {
    $("body").html(data.quoteText + " - " + data.quoteAuthor);
  .fail(function(err) {
    console.log('Error: ' + err.status);

This would be a simple call to Forismatic. The corsString is needed … err … because of CORS. I suggest you read up on that or check out a youtube video.

This will require you to load JQuery in codepen -> Settings/JavaScript/Quick-Add.

There are other ways to make an API call, but I find $.ajax to be the easiest to grasp at first.


This is a more verbose way, but avoids the need for the CORS workaround.

      url: "https://api.forismatic.com/api/1.0/",
      jsonp: "jsonp",
      dataType: "jsonp",
      data: {
        method: "getQuote",
        lang: "en",
        format: "jsonp"
    .done(function(data) {
      $("body").html(data.quoteText + " - " + data.quoteAuthor);
    .fail(function(err) {
      console.log('Error: ' + err.status);


ok I just spent the last hour looking for anything (free) that helps an have not found not a single course nor from Udacity Udemy courser edx or even class-central so could you please if you don’t mind explain to me how to implement the api in my random quote machine because I have found nothing on the topic.


Forismatic is not very well documented. There is nothing out there that will give you a step-by-step guide on how to implement it as far as I’m aware. What they offer is some basic guidance on the parameters you can add to an URL to contact their API and a source code example of how to use it at: https://api.forismatic.com/api/jsonp/

Visit that URL, right-click the page to view the source, and see how they implemented it. It may not make much sense :slight_smile: but to break it down and help analyze, you’ll see it’s a small chunk of code consisting of two lines of HTML:

<p id="quote"></p>
<i id="author"></i>

One JavaScript Function:

function parseQuote(response) {
  document.getElementById("quote").innerHTML = response.quoteText;
  document.getElementById("author").innerHTML = response.quoteAuthor;

And a script that calls the API:

<script src="https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&jsonp=parseQuote"></script>

So, to mimic this functionality, your tasks are:

  1. Add two lines of HTML, one for the quote text, another for the author.
  2. Create a function that runs when you click a button that adds the script to the page
  3. Write the data from the API to your two lines of HTML created in step 1.
  4. Delete the <script> so we can add it back and get more quotes later.

Steps 1 and 3 are already shown to us in the source code of that page, so all we have to do is figure out half of this puzzle :slight_smile: (steps 2 and 4). Step 2 is really the bulk of the challenge, so here are a couple of links that show how to do it:

For Step 4, I find it’s easiest to give the script an ID when you add it to the page, and then simply do:

document.getElementById('whateverIDYouGaveToYourScript').outerHTML = "";

All of that should be plenty to get you on the right path to making a fully functional random quote machine that you can style as desired. If you need some help along the way, I’ve added a few examples below:

Spoiler Code

Here’s an example of it all put together if you get frustrated and need to peek at some code:


This can also be done with jQuery - and they’ll take care of all the <script> embedding for us behind the scenes, so here are a couple more examples.



Hope this helps!


I found it was much less of a headache to code your own random quote machine, super easy and good practice to put javascript into a web page. There are plenty more opportunities to learn and work with better documented APIs in the later challenges.


thank you very much you saved me so much time and the project turned out pretty well.

if you want to see it here it is