So this is what I ended up with. I kept misspelling encodeURIComponent with"Componenet" and “encoded”. Ended up smashing my head against a wall going line by line but feel like my debug skillz are leveling up. I know there is a lot I could do to make it more streamlined so any js advice is more than welcome.
As for the HTML/Bootstrap I just didn’t want a bare page so I thought I would play around a little bit.
Thanks in advance!
I do notice that some of the quotes in this API run over the Twitter character limit and was wondering if anybody new a simple way to filter them so that they fall within this predefined limitation? Don’t know JSON/API stuff well enough to figure that out even though I had it in my basic specs for what I wanted to do
Instead of filtering quotes, I would truncate the quote string after it gets displayed, but before setting the Twitter link. Looks like a job for String.slice()
. Actually, one of the algorithm challenges has you doing something very much like this. As far as your code, I think it’s organized pretty well and readable. I’d say you could ditch window.open()
in favor of a normal <a>
link with the target="_blank"
attribute as pop-up blockers can prevent window.open()
from working, but there’s nothing wrong with the way you did it (in fact, you could pass it some more parameters to change the size of the window and its location when it pops-up). What makes me raise an eyebrow is that currentQuote
and currentAuthor
are defined without the var
keyword, which means the variables are on the global scope. This is the only reason you’re able to set the Twitter link like you are. I would actually prefer the code you have on line 21, myself, and then add that var
keyword to the variables. This will make truncating a string for the URL much easier, too.
Nice job, overall!