Posted on 04 October 2019 in dev

Fortune aims to be a minimalist fortune script. Quotes / fortunes with equations in MathJax are supported.

TL;DR: Go play with the code on github.

How it works

Generate a quote

The fortune function gets a random fortune from the quotes array and writes it in the HTML document.

function fortune(){
  /* calculate a random index */
  index = Math.floor(Math.random() * quotes.length);
  /* display the quotation */
  document.write("<p>" + quotes[index] + "</p>");

To do so in the html just add:

<script type="text/javascript" src="js/fortune.js" type="text/javascript"></script>
<script type="text/javascript">fortune();</script>

Add a new quote or modify a quote

Open the fortune.js file and modify the quotes array.

Add MathJax support

Add the following code to support MathJax quotes:

    MathJax = {
        tex: {
            inlineMath: [
                ['$', '$'],
                ['\\(', '\\)']
<script src=""></script>
<script id="MathJax-script" async src=""></script>


To see what fortune.js can do for you, check the index.html file in the example folder.