Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">

<!--@HEAD-->

<head>
    <title>A Random Quote Machine</title>
    <link rel="stylesheet" href="css/style.css">
    <meta charset="UTF-8">
    <meta name="description" content="A Random Quote Machine">
    <meta name="author" content="ridafatima">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!--#FONT_AWESOME-->
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU"
        crossorigin="anonymous">
    <!--#FONTS-->
    <link href="https://fonts.googleapis.com/css?family=Shadows+Into+Light" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Sacramento" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Great+Vibes" rel="stylesheet">
</head>

<!--@BODY-->

<body>
    <main>
        <div id="container">
            <div id="quote-box-container">
                <div id="quote-box">
                    <div id="text-box">
                        <p id="text" class="animation"></p>
                    </div>
                    <div id="author-box">
                        <p id="author" class="animation"></p>
                    </div>
                    <div id="buttons-box">
                        <div id="new-quote-box">
                            <a id="new-quote" class="animate">
                                <i id="reload" class="fas fa-redo-alt fa-2x"></i>
                            </a>
                        </div>
                        <div id="tweet-quote-box">
                            <a id="tweet-quote" href="twitter.com/intent/tweet" target="_blank">
                                <i id="twitter" class="fab fa-twitter fa-2x"></i>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </main>
    <div id="footer">
        <div id="logo-box">
            <img id="logo" src="https://res.cloudinary.com/billu/image/upload/v1537243527/Cats/logo.png" alt="logo">
        </div>
        <div id="footer-p">
            <p>In the memory of my beloved Billu</p>
            <p>Designed and Coded By <a href="#self">Rida</a></p>
        </div>
    </div>

    <!--#POSITION FIXED-->
    <img id="flower-1" src="https://res.cloudinary.com/billu/image/upload/v1537565831/Cats/flower.png">
    <img id="flower-2" src="https://res.cloudinary.com/billu/image/upload/v1537565831/Cats/flower.png">
    <img id="flower-3" src="https://res.cloudinary.com/billu/image/upload/v1537565831/Cats/flower.png">
    <img id="flower-4" src="https://res.cloudinary.com/billu/image/upload/v1537565831/Cats/flower.png">

    <!--#SCRIPTS-->
    <script src="js/index.js"></script>
    <!--#FREECODECAMP_TEST_SUITE-->
    <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
</body>

</html>
              
            
!

CSS

              
                /*///////////////////////////////////////////////////*/
/*//////////////////_CSS_RESET_//////////////////////*/
/*///////////////////////////////////////////////////*/

html {
    /* equals 1rem = 10px for most browsers*/
    font-size: 62.5%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-size: 1.6rem;
    font-weight: normal;
    line-height: 1.4;
    margin: 0;
    padding: 0;
    border: 0px;
}

*,
*::before,
*::after {
    box-sizing: inherit;
}

/*///////////////////////////////////////////////////*/
/*///////////////////_MAIN_CSS_//////////////////////*/
/*///////////////////////////////////////////////////*/

:root {
    --white: #FFF2E4;
    --pink: #EC5B55;
}

body {
    height: 100vh;
    width: 100%;
    display: grid;
    align-items: center;
    justify-content: center;
    background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.7));
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    transition: background 1s ease-in-out;
    -webkit-transition: background 1s ease-in-out;
    -moz-transition: background 1s ease-in-out;
    -ms-transition: background 1s ease-in-out;
    -o-transition: background 1s ease-in-out;
}

body::before {
    z-index: -1;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    content: "";
    width: 100%;
    height: 100vh;
    margin: 0;
    padding: 0;
    background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.7));
}

main {
    border: 10px solid;
    border-color: var(--pink);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 98vw;
    height: 96vh;
    padding: 4px;
    margin: 4px;
}

main::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    content: "";
    width: 100%;
    height: 100vh;
    margin: 0;
    padding: 0;
    background: url("https://res.cloudinary.com/billu/image/upload/v1537482100/Cats/logo22.png");
    background-repeat: repeat;
    opacity: 0.3;
}

#container {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 22px;
    border: 3px solid;
    border-color: var(--white);
    width: 96vw;
    height: 91vh;
    margin: 4px;
    padding: 4px;
}

#quote-box-container {
    grid-row: 1 / 2;
    grid-column: 1 / 2;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Purpose: debugging */
    background-color: purple;
}

#quote-box {
    height: 80vh;
    width: 85vw;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 60vh 4px 10vh 4px 66px;
}

#text-box {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    /* Purpose: debugging */
    background-color: burlywood;
}

#author-box {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
    /* Purpose: debugging */
    background-color: aqua;
}

#text {
    text-align: center;
    vertical-align: middle;
    font-size: 5.2rem;
    color: var(--white);
    font-family: 'Shadows Into Light', cursive;
    font-weight: 600;
    text-shadow: 2px 2px 4px #000000;
}

#text::before {
    /* Unicode for left quote " */
    content: '\201C';
    color: var(--pink);
}

#text::after {
    /* Unicode for right quote " */
    content: '\201D';
    color: var(--pink);
}

#author {
    text-align: center;
    vertical-align: middle;
    font-size: 4rem;
    color: var(--pink);
    font-weight: 900;
    font-family: 'Sacramento', cursive;
}

#author::before {
    /* Unicode for Dash */
    content: '\2012';
    color: var(--white);
}

#buttons-box {
    grid-column: 1 / 2;
    grid-row: 5 / 6;
    display: grid;
    grid-template-columns: 1fr 75px 75px 1fr;
    grid-template-rows: 1fr;
    /* Purpose: debugging */
    background-color: cadetblue;
}

#new-quote-box {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
    /* Purpose: debugging */
    background-color: greenyellow;
}

#tweet-quote-box {
    grid-column: 3 / 4;
    grid-row: 1 / 2;
    /* Purpose: debugging */
    background-color: yellow;
}

#new-quote-box,
#tweet-quote-box,
#author-box,
#text-box {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Buttons */
#new-quote,
#tweet-quote {
    width: 50px;
    height: 50px;
    border: 3px solid;
    border-color: var(--pink);
    border-radius: 50%;
    padding: 1px;
    color: var(--pink);
    background-color: var(--white);
    text-decoration: none;
    text-align: center;
    vertical-align: middle;
    font-size: 2rem;
    box-sizing: content-box;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

#new-quote:hover,
#tweet-quote:hover {
    background-color: var(--pink);
    color: var(--white);
    width: 56px;
    height: 56px;
    transition: width 0.1s, height 0.1s;
    -webkit-transition: width 0.1s, height 0.1s;
    -moz-transition: width 0.1s, height 0.1s;
    -ms-transition: width 0.1s, height 0.1s;
    -o-transition: width 0.1s, height 0.1s;
}

/* ANIMATION */
@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.animate,
.animate:hover {
    animation-name: rotate;
    animation-duration: 1s;
    animation-fill-mode: backwards;
    animation-iteration-count: 1;
    animation-timing-function: ease-in;
    animation-play-state: running;
}

.animate:active {
    animation-name: none !important;
}

#footer {
    /* Purpose: debugging */
    background-color: lawngreen;
    position: fixed;
    z-index: 2;
    text-align: center;
    vertical-align: middle;
    width: 350px;
    margin-top: 1px;
    margin-bottom: 1px;
    background-color: var(--pink);
    font-family: 'Great Vibes', cursive;
    font-size: 2rem;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    display: grid;
    grid-template-columns: 80px 1fr;
    grid-template-rows: 1fr;
    border: 4px solid;
    border-color: var(--white);
    border-style: double;
}

#footer-p>p {
    color: var(--white);
    line-height: 0.4;
    margin: 0;
    padding-bottom: 8px;
    padding-top: 10px;
}

#footer-p>p>a {
    font-family: inherit;
    color: var(--white);
    text-decoration: none;
}

#logo {
    width: 40px;
    height: 40px;
}

#logo-box {
    grid-row: 1 / 2;
    grid-column: 1 / 2;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Purpose: debugging */
    background-color: aqua;
}

#footer-p {
    grid-row: 1 / 2;
    grid-column: 2 / 3;
    /* Purpose: debugging */
    background-color: yellow;
}

#flower-1,
#flower-2,
#flower-3,
#flower-4 {
    position: fixed;
    z-index: 100;
    width: 100px;
    height: 100px;
}

#flower-1 {
    top: 0;
    left: 0;
}

#flower-2 {
    top: 0;
    right: 0;
    transform: rotate(180deg);
    -webkit-transform: rotate(180deg);
    -moz-transform: rotate(180deg);
    -ms-transform: rotate(180deg);
    -o-transform: rotate(180deg);
}

#flower-3 {
    bottom: 0;
    left: 0;
}

#flower-4 {
    bottom: 0;
    right: 0;
    transform: rotate(180deg);
    -webkit-transform: rotate(180deg);
    -moz-transform: rotate(180deg);
    -ms-transform: rotate(180deg);
    -o-transform: rotate(180deg);
}

#text,
#author {
    opacity: 0;
}

/* Fade-In: The animation defined */
@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Fade-Out: The animation defined */
@keyframes fade-out {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* The animation class applied to text and author */
.animation {
    animation-name: none;
    animation-duration: 1s;
    animation-delay: 0s;
    animation-fill-mode: forwards;
    animation-timing-function: ease;
    animation-direction: normal;
    animation-iteration-count: 1;
    animation-play-state: running;
}


/* 
    * IMPORTANT: Comment this to see colors of grid for debugging
    * Always keep at the end (before media queries)
    * purpose: debugging
*/
#quote-box-container,
#buttons-box,
#author-box,
#text-box,
#new-quote-box,
#tweet-quote-box,
#footer-p,
#logo-box {
    background-color: initial;
    border: none;
}

/*///////////////////////////////////////////////////*/
/*//////////////////_MEDIA_QUERIES_//////////////////*/
/*///////////////////////////////////////////////////*/

@media only screen and (max-width: 900px) {

    #text {
        font-size: 4.4rem;
        line-height: 1.3;
    }

    #flower-1,
    #flower-2,
    #flower-3,
    #flower-4 {
        width: 60px;
        height: 60px;
    }
}

@media only screen and (max-width: 600px) {

    #text {
        font-size: 4rem;
    }
}

@media only screen and (max-width: 460px) {

    #text {
        font-size: 3.5rem;
        line-height: 1.3;
    }

    #footer {
        grid-template-columns: 60px 1fr;
        width: 300px;
    }

    #flower-1,
    #flower-2,
    #flower-3,
    #flower-4 {
        width: 40px;
        height: 40px;
    }

}

@media only screen and (max-width: 360px) {

    #text {
        font-size: 3rem;
    }

    #author {
        font-size: 3rem;
    }

    #footer {
        grid-template-columns: 50px 1fr;
        width: 260px;
        font-size: 1.7rem;
        line-height: 0.3;
    }

    #flower-1,
    #flower-2,
    #flower-3,
    #flower-4 {
        width: 35px;
        height: 35px;
    }

}

@media only screen and (max-width: 315px) {

    #footer {
        grid-template-columns: 48px 1fr;
        width: 240px;
        font-size: 1.5rem;
        line-height: 0.3;
    }

    #flower-1,
    #flower-2,
    #flower-3,
    #flower-4 {
        width: 30px;
        height: 30px;
    }

}

@media only screen and (max-height: 625px) {

    #text {
        line-height: 1.2;
    }

    #quote-box {
        height: 83vh;
        width: 85vw;
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: 59vh 3px 10vh 1px 55px;
    }

    /* Buttons */
    #new-quote,
    #tweet-quote {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
    }

    #new-quote:hover,
    #tweet-quote:hover {
        width: 46px;
        height: 46px;
    }

    #buttons-box {
        grid-template-columns: 1fr 56px 56px 1fr;
    }

}
              
            
!

JS

              
                "use strict";

//////////////////////////////////////////////////////////////////
/////////////////////////_DATA_SET_///////////////////////////////
//////////////////////////////////////////////////////////////////

var quotes = [

    {
        text: "Of all God’s creatures, there is only one that cannot be made slave of the leash. That one is the cat.",
        author: "Mark Twain",
        image: "https://res.cloudinary.com/billu/image/upload/v1537232705/Cats/00.jpg"
    },

    {
        text: "I have studied many philosophers and many cats. The wisdom of cats is infinitely superior.",
        author: "Hippolyte Taine",
        image: "https://res.cloudinary.com/billu/image/upload/v1536970923/Cats/01.jpg"
    },

    {
        text: "The way to get on with a cat is to treat it as an equal – or even better, as the superior it knows itself to be.",
        author: "Elizabeth Peters",
        image: "https://res.cloudinary.com/billu/image/upload/v1536970849/Cats/02.jpg"
    },

    {
        text: "There are no ordinary cats.",
        author: "Colette",
        image: "https://res.cloudinary.com/billu/image/upload/v1536971105/Cats/03.jpg"
    },

    {
        text: "What greater gift than the love of a cat.",
        author: "Charles Dickens",
        image: "https://res.cloudinary.com/billu/image/upload/v1536970825/Cats/04.jpg"
    },

    {
        text: "I have lived with several Zen masters -- all of them cats.",
        author: "Eckhart Tolle",
        image: "https://res.cloudinary.com/billu/image/upload/v1536970857/Cats/05.jpg"
    },

    {
        text: "I believe cats to be spirits come to earth.",
        author: "Jules Verne",
        image: "https://res.cloudinary.com/billu/image/upload/v1536970823/Cats/06.jpg"
    },

    {
        text: "As anyone who has ever been around a cat for any length of time well knows cats have enormous patience with the limitations of the human kind.",
        author: "Cleveland Amory",
        image: "https://res.cloudinary.com/billu/image/upload/v1536971230/Cats/07.jpg"
    },

    {
        text: "The smallest feline is a masterpiece.",
        author: "Leonardo da Vinci",
        image: "https://res.cloudinary.com/billu/image/upload/v1536971263/Cats/08.jpg"
    },

    {
        text: "A cat has absolute emotional honesty.",
        author: "Ernest Hemingway",
        image: "https://res.cloudinary.com/billu/image/upload/v1536971388/Cats/09.jpg"
    },

    {
        text: "Cats choose us, we don’t own them.",
        author: "Kristin Cast",
        image: "https://res.cloudinary.com/billu/image/upload/v1536971302/Cats/10.jpg"
    },

    {
        text: "Way down deep, we’re all motivated by the same urges. Cats have the courage to live by them.",
        author: "Jim Davis",
        image: "https://res.cloudinary.com/billu/image/upload/v1537231488/Cats/11.jpg"
    },

    {
        text: "Those who’ll play with cats must expect to be scratched.",
        author: "Miguel de Cervantes",
        image: "https://res.cloudinary.com/billu/image/upload/v1537231518/Cats/12.jpg"
    },

    {
        text: "Cats know how to obtain food without labor, shelter without confinement, and love without penalties.",
        author: "Walter Lionel George",
        image: "https://res.cloudinary.com/billu/image/upload/v1537231540/Cats/13.jpg"
    },

    {
        text: "Cats have it all — admiration, an endless sleep, and company only when they want it.",
        author: "Rod Mckuen",
        image: "https://res.cloudinary.com/billu/image/upload/v1537231571/Cats/14.jpg"
    },

    {
        text: "The problem with cats is that they get the same exact look whether they see a moth or an axe-murderer.",
        author: "Paula Poundstone",
        image: "https://res.cloudinary.com/billu/image/upload/v1537231589/Cats/15.jpg"
    },

    {
        text: "There are two means of refuge from the miseries of life: music and cats.",
        author: "Albert Schweitzer",
        image: "https://res.cloudinary.com/billu/image/upload/v1537231648/Cats/16.jpg"
    },

    {
        text: "In ancient times cats were worshipped as gods; they have not forgotten this.",
        author: "Terry Pratchett ",
        image: "https://res.cloudinary.com/billu/image/upload/v1537231674/Cats/17.jpg"
    },

    {
        text: "Time spent with cats is never wasted.",
        author: "Sigmund Freud",
        image: "https://res.cloudinary.com/billu/image/upload/v1537231714/Cats/18.jpg"
    },

    {
        text: "Cats are the runes of beauty, invincibility, wonder, pride, freedom, coldness, self-sufficiency, and dainty individuality.",
        author: "H. P. Lovecraft",
        image: "https://res.cloudinary.com/billu/image/upload/v1537231761/Cats/19.jpg"
    }

];

//////////////////////////////////////////////////////////////////
/////////////////////////_GLOBAL_VARIABLES_///////////////////////
//////////////////////////////////////////////////////////////////

var remainingQuotes = Array.from(quotes); // copy of original quotes array

var hasDisplayedFirstQuote = false; // boolean flag for main function

var img = []; // variable for imagePreLoader function

//////////////////////////////////////////////////////////////////
/////////////////////////_FUNCTION_DECLARATIONS_//////////////////
//////////////////////////////////////////////////////////////////

// RANDOM INTEGER FUNCTION
function getRandomInt(arraySize) {
    return Math.floor(Math.random() * Math.floor(arraySize));
}

// INDEX OF OBJECT IN AN ARRAY FUNCTION
function indexOfObject(arr, obj) {
    let objKeyArr = Object.keys(obj);
    for (let i = 0; i < arr.length; i++) {
        for (let k = 0; k < objKeyArr.length; k++) {
            if (arr[i].hasOwnProperty(objKeyArr[k]) === true) {
                if (obj[objKeyArr[k]] != arr[i][objKeyArr[k]]) {
                    break;
                }
                if (k === (objKeyArr.length - 1)) {
                    return i;
                }
            }
        }
    }
    return -1;
}

// TEXT FOR TWITTER FUNCTION
function textTweet(text, author) {
    let tweetText = "";
    if ((text.length + author.length) > 280) {
        tweetText = text.slice(0, (280 - (author.length + 3)));
        tweetText = tweetText + "...";
    } else {
        tweetText = text;
    }
    return tweetText;
}

// FADE-IN ANIMATION
function fadeIn() {
    document.getElementById("text").style.animationName = "fade-in";
    document.getElementById("author").style.animationName = "fade-in";
}

// FADE-OUT ANIMATION
function fadeOut() {
    document.getElementById("text").style.animationName = "fade-out";
    document.getElementById("author").style.animationName = "fade-out";
}

// SET QUOTE
function setQuote(text, author, image) {
    document.getElementById("text").innerHTML = text;
    document.getElementById("author").innerHTML = author;
    document.body.style.backgroundImage = "url(" + image + ")";
    document.getElementById("tweet-quote").href = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent('"' + textTweet(text, author) + '" ' + author);
}

// IMAGE PRE-LOADER FUNCTION
function imagePreLoader(imageArray) {
    for (let i = 0; i < imageArray.length; i++) {
        img[i] = new Image();
        img[i].src = imageArray[i].image;
    }
}

// RANDOM QUOTE FUNCTION
function new_Quote() {

    let random = getRandomInt(remainingQuotes.length);
    let currentQuote = remainingQuotes.splice(random, 1)[0];

    if (remainingQuotes.length === 0) {
        remainingQuotes = Array.from(quotes);
        let x = indexOfObject(remainingQuotes, currentQuote);
        remainingQuotes.splice(x, 1);
    }

    setQuote(currentQuote.text, currentQuote.author, currentQuote.image);
}

// MAIN FUNCTION
function main() {
    if (!hasDisplayedFirstQuote) {
        new_Quote();
        fadeIn();
        hasDisplayedFirstQuote = true;
    } else {
        fadeOut();
        setTimeout(new_Quote, 1000);
        setTimeout(fadeIn, 1000);
    }
}

//////////////////////////////////////////////////////////////////
/////////////////////////_FUNCTION_CALLING_///////////////////////
//////////////////////////////////////////////////////////////////
window.onload = function () {
    imagePreLoader(quotes);
    main();
};

document.getElementById("new-quote").onclick = function () {
    main();
};
              
            
!
999px

Console