Generate Random Quotes from a Text File

So to do that, you need a text file full of quotes. HAHAHA
Separated by new line.

$('#btn_modal').click(function () {
    var num = 0;
        url: "",
        type: "GET",
        dataType: "text",
        beforeSend: function () {
            $('#kowts').show().html('<img src="" />');
        success: function (t) {
            var lines = t;
            var lineArr = lines.split('\n');
            num = Math.floor(Math.random() * lineArr.length);
        error: function(){

Split the quotes from text file by "\n" (new line), then get its length and generate a random number between 0 to maximum length. Then use the generated number as index to get the quote on that particular line. Display it in your HTML element.

<button id="btn_modal">Give me a Quote</button>
<p id="kowts"></p>

#kowts {

BTW, the text file that I used is not mine, got from somewhere else I forgot the link. (:

Popular posts from this blog

Add/Subtract Single Digit Number in Assembly Language

Set table width to 100% on PDF export in Datatables