Critique my Random Quote Machine

Critique my Random Quote Machine
0

#1

Hi there. I’ve finished my random quote machine. When I finished with it, I was initially please with the result. It worked well (or so I though), but under more thorough examination it seems to have a number of significant problems:

  • Firstly, I couldn’t figure a way to remove the quotation symbols from around the originator of the quote. I tried .replace but to no avail.

  • Secondly, it appears that the quotes seemingly aren’t refreshed when I share the code with other people… Could anyone she any light on this?

  • Thirdly, if there is no author returned ("") with the JSON, my if statement doesn’t catch this. Is there a way to make the if statement work? I tried assigning it to a variable, but again to no avail.

I had a look at the example quote machine and saw that it used an AJAX implementation?

http://codepen.io/hughwin/pen/PGNqNr


#2

Running the code on Microsoft’s Edge browser it now runs flawlessly. However, when I go back to Chrome, I get the same quote over and over gain. Could it be something to do with AdBlocker or something?


#3

For people looking for a solution to the only loading a single quote problem, if you add
$.ajaxSetup({ cache: false }); after $(document).ready(function()), it stops the quotes been taken from the cache.

I have now sorted all the problems with my JavaScript. My pages looks as ugly as hell, but at least it works. I may try to beautify it later.


#4

I think you’re getting quote marks around the quote and the author because you JSON.stringify()ed them. You can just refer to them directly, like

$("#message").html(json.quoteAuthor)...
// also eliminates the use of `.slice()`

I still haven’t encountered a quote with no author.


#5

There’s no an if statement in there which prevents the author being returned as “”

I will have a look at changing the code later, because admittedly, it does look a lot cleaner.