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

              
                <body>
    <script src="quote.js" type="text/babel"></script>
    <div id="root"></div>
    <div class="footer-container">
        <footer>

            <p class="footer-text">Created by Lucas Ezequiel Ojeda for the <a class="footer-link"
                    href="https://learn.freecodecamp.org/front-end-libraries/front-end-libraries-projects/build-a-random-quote-machine"
                    title="Build a Random Quote Machine section in FreeCodeCamp">"Build a Random Quote Machine
                    challenge"</a>at FreeCodeCamp (July, 2019)</p>

            <a class="footer-link" href="https://github.com/lezojeda" target="_blank" title="Link to my GitHub profile">
                <i class="fab fa-github fa-4x profile-icon"></i></a>
            <a class="footer-link" href="https://www.freecodecamp.org/lezojeda" target="_blank"
                title="Link to my FreeCodeCamp profile">
                <i class="fab fa-free-code-camp fa-4x profile-icon"></i></a>
        </footer>
    </div>
</body>
              
            
!

CSS

              
                * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

body {
    background-color: #b99667;
}

#root {
    display: flex;
    justify-content: center;
}

#quote-box {
    background-color: #e9decf;
    border-radius: 3%;
    box-shadow: 10px 10px 10px rgba(0, 0, 0, 0.3);
    margin: 0 auto;
    padding: 50px 50px 30px 50px;
    position:absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 600px;
}

#quote-box h1 {
    font-size: 1.8em;
}

#quote-box h3 {
    font-size: 1.3em;
    margin-bottom: 15px;
}

#text {
    color: #383838;
    font-family: 'Noto Serif JP', serif;
    margin-bottom: 15px;
    text-align: center;
}

.quote-icon {
    padding-right: 10px;
}

#author {
    color: #383838;
    font-family: 'Volkhov', serif;
    text-align: right;
}

.button-container {
    display:flex;
    margin-top: 15px;
    justify-content:flex-end;
}

#new-quote {
    background-color: #5D5852;
    border-radius: 10%;
    color: #e9decf;
    cursor: pointer;
    padding: 10px;
    transition: 0.3s ease;
}

#new-quote:hover {
    background-color: rgba(93, 88, 82, 0.671);
}

.fa-twitter-square {
    color: #0198a0;
    margin-right: 10px;
    transition: 0.3s ease;
}

.fa-twitter-square:hover {
    color: #00acb563;
}

footer {
    bottom:0;   
    font-size: 0.7em;
    left:0;
    padding-bottom:5px;
    position:absolute;
    right:0;
    text-align:center
}

.footer-link {
    color: rgb(0, 0, 0);
    transition: 0.3s;
    text-decoration:underline;
}
.footer-link:hover {
    color: rgba(0, 0, 0, 0.836);
    text-decoration: none
}

.profile-icon {
    padding-right:5px;
}

@media only screen and (max-width: 400px){
    #quote-box {
        padding: 15px 15px 7.5px 15px;
        width: 85%;
    }
    #quote-box h1 {
        font-size: 1em;
    }

    #quote-box h3 {
        font-size: 0.8em;
        text-align:center;
    }

    .button-container {
        justify-content: center;
    }

    .footer-text {
        display:none;
    }

}

@media only screen and (max-height: 500px) {
    #quote-box {
        margin-top: 20px;
        position:static;
        top:0;
        transform: none;
    }

    #quote-box h1 {
        font-size: 1em;
    }
    
    #quote-box h3 {
        font-size: 0.8em;
        margin-bottom: 15px;
    }

    .button-container {
        margin-top: 5px;
    }

    #new-quote {
        padding: 5px;
        font-size: 0.8em;
    }

    .footer-text {
        display:none;
    }
}
              
            
!

JS

              
                const quotes_list = [
    {
        quote: "I'm not sure if I was the first man in space or the last dog.",
        source: "- Yuri Gagarin",
        year: "1961",
        tags: "Humor",
    },
    {
        quote: "'We’ll never survive!' 'Nonsense. You’re only saying that because no one ever has.'",
        source: "- William Goldman",
        citation: "The Princess Bride",
        year: "1987",
        tags: "Inspirational",
    },
    {
        quote: "You know, Hobbes, some days even my lucky rocket ship underpants don't help.",
        source: "- Bill Watterson",
        citation: "Calvin and Hobbes",
        tags: "Humor"
    },
    {
        quote: "You people talk about the living and the dead as if they were two mutually exclusive categories. As if you cannot have a river that is also a road, or a song that is also a color.",
        source: "- Neil Gaiman",
        citation: "American Gods",
        year: "2001",
        tags: "Spirituaity"
    },
    {
        quote: "Yet man will never be perfect until he learns to create and destroy; he does know how to destroy, and that is half the battle.",
        source: "- Alexandre Dumas",
        citation: "The Count of Monte Cristo",
        year: "1844",
        tags: "Humanity"
    },
    {
        quote: "Never let your sense of morals prevent you from doing what is right.",
        source: "- Isaac Asimov",
        citation: "Foundation",
        year: "1951",
        tags: "Spirituality"
    },
    {
        quote: "Let's think the unthinkable, let's do the undoable. Let us prepare to grapple with the ineffable itself, and see if we may not eff it after all.",
        source: "- Douglas Adams",
        citation: "Dirk Gently's Holistic Detective Agency",
        year: "1987",
        tags: "Inspirational",
    },
    {
        quote: "A creative man is motivated by the desire to achieve, not by the desire to beat others.",
        source: "- Ayn Rand",
        tags: "Inspirational"
    },
    {
        quote: "I'm not dumb. I just have a command of thoroughly useless information.",
        source: "- Bill Watterson",
        citation: "Calvin and Hobbes",
        tags: "Humor"
    },
    {
        quote: "A bone to the dog is not charity. Charity is the bone shared with the dog, when you are just as hungry as the dog.",
        source: "- Jack London",
        tags: "Humanity"
    },
    {
        quote: "You have power over your mind - not outside events. Realize this, and you will find strength.",
        source: "- Marcus Aurelius (roman emperor)",

    },
    
    {
        quote: "Happiness is when what you think, what you say, and what you do are in harmony.",
        source: "- Mahatma Gandhi",

    },
    {
        quote: "Every one of us is, in the cosmic perspective, precious. If a human disagrees with you, let him live. In a hundred billion galaxies, you will not find another.",
        source: "- Carl Sagan",

    },
    {
        quote: "I could either watch it happen or be a part of it.",
        source: "- Elon Musk",

    },
    {
        quote: "Síganme, no los voy a defraudar.",
        source: "- Carlos Saúl Menem",
        year: "1989"
    },
    {
        quote: "¡Música! Melancólico alimento para los que vivimos de amor.",
        source: "- Julio Cortázar",

    },
    {
        quote: "Me cortaron las piernas.",
        source: "- Diego Maradona",
        year: "1994"

    },
    {
        quote: "Hombre, pueblo, nación y estado: todo está en los humildes bancos de la escuela.",
        source: "- Domingo Faustino Sarmiento",

    },
    {
        quote: "When you're at the end of your rope, tie a knot and hold on.",
        source: "- Theodore Roosevelt",

    },
    {
        quote: "Scientific truth is beyond loyalty and disloyalty.",
        source: "- Isaac Asimov, la Fundación",
        year: "1951"

    },
    {
        quote: "But man is not made for defeat. A man can be destroyed but not defeated.",
        source: "- Ernest Hemingway",
    },
    {
        quote: "You cannot shake hands with a clenched fist.",
        source: "- Indira Gandhi"
    },
    {
        quote: "There is nothing permanent except change.",
        source: "- Heraclitus"
    },

    {
        quote: "Do not mind anything that anyone tells you about anyone else. Judge everyone and everything for yourself.",
        source: "- Henry James",

    },
    {
        quote: "There is no charm equal to tenderness of heart.",
        source: "- Jane Austen",

    },
    {
        quote: "Learning never exhausts the mind.",
        source: "- Leonardo da Vinci",

    },
    {
        quote: "There is only one corner of the universe you can be certain of improving, and that's your own self.",
        source: "- Aldous Huxley",

    },
    {
        quote: "Tell me and I forget. Teach me and I remember. Involve me and I learn.",
        source: "- Benjamin Franklin",
    },
    
];

class QuoteBox extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            quote_number: Math.floor((Math.random() * quotes_list.length))
        }
        this.handleClick = this.handleClick.bind(this);
    }

    handleClick() {
        this.setState({
            quote_number: Math.floor((Math.random() * quotes_list.length))
        })
    }

    render() {
        return (
            <div id="quote-box">

                <h1 id="text">
                    <i class="fas fa-quote-left quote-icon"></i>{ quotes_list[this.state.quote_number]['quote']}
                </h1>

                <h3 id="author">
                    {quotes_list[this.state.quote_number]['source'] +
                        (quotes_list[this.state.quote_number]['year'] == undefined ? "" : (", " + quotes_list[this.state.quote_number]['year']))
                    } 
                    {/*Some quotes don't have year so it checks if undefined which in case returns just empty string */}
                </h3>

                <div className="button-container">
                    
                    <a id="tweet-quote"
                        href={'https://twitter.com/intent/tweet?text=' + quotes_list[this.state.quote_number]['quote'] + ' ' + quotes_list[this.state.quote_number]['source']}
                        target = "_blank" title = "Tweet this quote">
                        <i className="fab fa-twitter-square fa-3x"></i>
                    </a>

                    <button id="new-quote" onClick={this.handleClick} title = "Get a new quote">New quote</button>
                </div>

            </div>
        )
    }
}

ReactDOM.render(<QuoteBox />, document.getElementById('root'));
              
            
!
999px

Console