My JavaScript iambic pentameter generator is among the most popular programming posts on Home for Fiction. It’s a really “alpha” piece of code which I haven’t worked on since I made that first version. But here’s a little something to compensate: let’s make a rhyming JavaScript Shakespearean sonnet mixer!
Unlike the iambic pentameter generator, this JavaScript Shakespearean sonnet mixer returns much more coherent results. After all, the code doesn’t need to generate any random text. It simply shuffles the Bard’s own production.
For a relevant project, also take a look at my poem shuffler.
To keep things simple, I decided to have it generate only two rhyming lines. The more the lines, the slower it would get – and the more likely it would not find any rhyming pairs.
Relax, I haven’t gone crazy. If you thought someone like me suddenly started believing in horoscopes, you’re wrong. Yes, in this post I’ll show you how to make a JavaScript horoscope generator. But the post is about linguistics, programming, and maybe psychology; not astrology.
If anything, my goal making this JavaScript horoscope generator was to show how ridiculously easy it is to produce accurate-seeming phrases that appear to apply to everyone’s individual situation. Simple answers to complex questions, really.
There’s actually a bit of literary background in this, believe it or not. There is a scene in my book The Other Side of Dreams, where the protagonist makes fun of a Tarot card reader:
Indeed, Ahmed thought, he could tell Anna pretty much everything the woman had said, without using any cards. “You are coming up a difficult fork in the road of your life, considering your options. Part of you would like to be more daring, but you are aware of the importance of being cautious. You are inspired by strong feelings, and you will be rewarded in love thanks to your tenacity. Remember to be true to yourself, although you should also be diplomatic, especially considering matters related to business, money, or agreements.” There, it can’t get any easier than that.
And so, I decided to combine my background in languages and my interest in programming. This JavaScript horoscope generator was the result!
In other words, there aren’t “areas” of creativity, neatly isolated from one another. There isn’t a creativity related to fiction writing, another related to academic writing, and yet another related to developing Android apps. There is only one form of creativity, and the more efficiently you can combine its different facets, the better.
Chances are, if you found this post you care more about the JavaScript code, so I won’t tire you with theorizing – if you’re interested in philosophy, feel free to take a look at the many posts dealing with philosophical musings.
Having said that, this post still wants to make a more theoretical point, namely that what appears difficult and incomprehensible (like coding) can be very simple. Therefore, I will be a bit… verbose in my explanations, trying to help beginners keep up.
So, let’s get to the details of how to make a random quote generator written in JavaScript.