A Ron Swanson quote machine

A Ron Swanson quote machine
0.0 0


Submitted and just calling it done for now. I do want to come back later to add some visual things like some box-shadow and some text fading. Any feedback to improve the code appreciated!


The API sends back a response in JSON format. You are using $.getJSON, so it will convert the response to an applicable object/array which is accessible by referencing the json argument you are using within the callback function. It just so happens that this API sends back an array with one element for a response.

There is no need to convert json to a string and use the filters. So, you can replace all of the following:

        var raw = JSON.stringify(json);
        raw = raw.split("");
        aQuote = raw.filter(word => word != ']');
        aQuote = aQuote.filter(word => word != '[');

with the following:

       $("#quotes").html('"'+json[0]+'"'); // nests 1st element of json between double quotes


Thank you! That is much cleaner. I’ve made those changes and was testing it a bit. It makes sense. The nesting part made me pause slightly but realized it was concatenating. (It’s also 5am where I am).

Thanks for the info about $.getJSON parsing the results. I did some further reading and found this on the official jQuery site, does it still use $.parseJSON to do this? Reading the $.praseJSON() method, it states that it’s deprecated. Just asking out of curiosity.

“The success callback is passed the returned data, which is typically a JavaScript object
or array as defined by the JSON structure and parsed using the $.parseJSON() method.
It is also passed the text status of the response.”