Random Quotes Machine

In this example below you will see how to do a Random Quotes Machine with some HTML / CSS and Javascript

This is a random quotes machine for FreeCodeCamp.

Thumbnail
This awesome code was written by r3b311i0n, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright r3b311i0n ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Random Quotes Machine</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css'>
<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css'>

      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <body class="grey darken-4">
<div class="container">
    <div class="row">
        <div class="s12">
            <div class="quoteFrame card-panel orange lighten-2 white-text">
                <h1 class="quote"></h1>
                <cite class="quoteAuthor"></cite>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="s6">
            <div class="newQuote">
                <a href="#" class="newQuoteButton waves-effect waves-light btn-large btn-floating orange">
                    <i class="fa fa-quote-left"></i>
                </a>
            </div>
        </div>
        <div class="s6">
            <div class="blueBird">
                <a href="" class="tweetButton waves-effect waves-light btn-large btn-floating orange"
                   target="_blank">
                    <i class="fa fa-twitter"></i>
                </a>
            </div>
        </div>
    </div>
</body>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/js/materialize.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/r3b311i0n/random-quotes-machine-mAWLEN */
/* 
github: https://github.com/r3b311i0n/Random_Quote_Machine
*/

body {
    font-family: "Roboto", serif;
    margin: auto;
    padding: 1rem;
}

.quoteAuthor {
    float: right;
    padding-right: 3rem;
}

.quoteFrame {
    padding-bottom: 3rem;
    opacity: 0;
}

.blueBird .btn-floating {
    bottom: 5em;
    right: 6em;
    position: fixed;
}

.newQuote .btn-floating {
    bottom: 5em;
    left: 6em;
    position: fixed;
}

/*Downloaded from https://www.codeseek.co/r3b311i0n/random-quotes-machine-mAWLEN */
const API = "https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?&key=";
const TWITTER = "https://twitter.com/intent/tweet?text=";

var getQuote = function () {
    var key = Math.floor(Math.random() * (999999 - 1 + 1)) + 1;

    $.getJSON(API + key, function (quoteJson) {
        $(".quote").html("\"" + quoteJson["quoteText"] + "\"");

        if (quoteJson["quoteAuthor"] != "") {
            $(".quoteAuthor").html(" - " + quoteJson["quoteAuthor"]);
        }

        $(".quoteFrame").fadeIn(600);
    });
};

var tweetQuote = function () {
    var tweetEncode = encodeURI($(".quote").html() + " " + $(".quoteAuthor").html());

    $(".tweetButton").attr("href", TWITTER + tweetEncode);
};

$("div .newQuoteButton").on("click", function () {
    $(".quoteFrame").fadeOut(600, getQuote);
});

$("div .tweetButton").on("click", function () {
    tweetQuote();
});

$(document).ready(function () {
    $(".quoteFrame").hide().animate({opacity: 100}, 600, getQuote);
});

Comments