Trouble with random quote machine project

Trouble with random quote machine project
0

#1

Hi. I have been trying to do this project for a while, but I cant find out why this isnt working. can someone please help me with this. thanks.


#2

I have tried to access this http://quote.fm/labs website you’re requesting your quotes from, but it does not exist. Try using a different quotes retrieval API?

Here is a working Quotes API.

JSON response sample:

{
"author": "Robert Sewell",
"id": 41,
"quote": "If Java had true garbage collection, most programs would delete themselves upon execution.",
"permalink": "http://quotes.stormconsultancy.co.uk/quotes/41"
}

Good luck.


#3

Thanks for the API. i tried using it, but for some reason it still doesnt work. Is it something with my code?


#4

Look at your spelling of stringify. Change that and then see what you have to work with. :slight_smile:


#5

As @escottalexander indicated at line 6:

$("p").html(JSON.stringfly(data)); // stringfly !== stringify

You got a spelling error.

Now as soon as you fix that, you should be able to display your JSON values.
You should see something like this whenever you click your button:

Not the best quotes display. This is happing because you’re throwing all of the JSON data into the p element. Let’s console.log/display your JSON data on your browser:

As you are using the link that requests lots of quotes; you’re receiving a handful per request. (Find a different link from the API documentation if you want a single quote per request, random quotes…etc.). But, that’s not a big deal. Now you need to access the quotes one by one for a better display.

How can you access objects?

You access the objects by first specifying the array index (As they’re nested inside an array) and then you access the objects by using one of the two methods for object access. You have learned all of that in FreeCodeCamp:

Here is an example of accessing the first quote: data[0].quote
Goodluck.


#6

Thank you so much. i have been stuck on this problem for so long. :slight_smile: i didnt look for spelling mistakes.