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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    
        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    </head>
    <body>
        <div id="root" class="fluid-container" style="width: 100%">

            <div class="col-sm-12 mx-auto text-center" style="width: 100%; height: 30%"></div>

            <div id="quote-box" class="row" style="height: auto">
                <div class="col-sm-2"></div>
                <div class="card col-sm-8">
                    <div class="card-header text-center"><font class="h3">Random Quote Machine</font>
                            <div class="mx-auto align-center">

                                <button class="btn btn-default btn-secondary m-1 font-weight-bold" id="new-quote">
                                    New Quote
                                    <span id="loadingSpinner" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
                                </button>
                                <a id="tweet-quote" target="_blank"><button 
                                    class="btn btn-default btn-outline-secondary m-1" 
                                    data-toggle="tooltip" 
                                    data-placement="bottom" title="Share on Twitter"
                                    id="tweet-btn">
                                    <img src="https://img.icons8.com/ios/40/000000/twitter--v1.png">
                                </button></a>
                                <a id="tumblr-quote" target="_blank"><button 
                                    class="btn btn-default btn-outline-secondary m-1"
                                    data-toggle="tooltip" 
                                    data-placement="bottom" title="Share on Tumblr" 
                                    id="tumblr-quote">
                                    <img src="https://img.icons8.com/ios/40/000000/tumblr--v1.png">
                                </button></a>
                            </div>
                    </div> 
                    <div id="content">
                        <span class="font-weight-bold h3">&ldquo;</span>
                        <span id="text" class="blockquote font-weight-bold"></span>
                        <span class="font-weight-bold h3">&rdquo;</span>
                        <div id="author" class="blockquote-footer text-right"></div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <!--Test Script-->
    <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
</html>
              
            
!

CSS

              
                body {
    background: lightgray;
}

#quote-box {
    padding: 10px;
}

.card {
    background: rgb(226, 223, 223);
    padding: 10px;
}

.btn-outline-secondary {
    border: none;
}

.icons8-twitter { 
    display: inline-block;
    width: 30px;
    height: 30px;
    background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0i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zLTAuMDI1LTAuOTQ1QzM5Ljc2MywxNS4xOTcsNDEuMDEzLDEzLjkwNSw0MiwxMi40MjkiPjwvcGF0aD48L3N2Zz4=') 50% 50% no-repeat;
    background-size: 100%; 
}
              
            
!

JS

              
                // const switchQuote = () => {
//     $.ajax({
//         // url: 'http://quotes.stormconsultancy.co.uk/random.json',
//         // url: 'https://api.whatdoestrumpthink.com/api/v1/quotes/random',
//         url: 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?',
//         data: {format: 'jsonp'},
//         error: function() {
//             console.log('An error has occurred');
//         },
//         dataType: 'jsonp',
//         success: function(data) {
//             console.log(`Fetched Quote Sucessfully`)
//             console.log(data)
//             $("#quote").html(data.quote)
//             $("#quote-source").html(`---${data.author}`)
//         },  
//         type: 'GET'
//     });
// }

const switchQuote = () => {

    //Show loading spinner
    $("#loadingSpinner").show()

    //Fetch new quote
    $.ajax({
        url: 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?',
        data: {format: 'jsonp'},
        error: function() {
            console.log('An error has occurred');
        },
        dataType: 'jsonp',
        success: function(data) {
            console.log(`Fetched Quote Sucessfully`)
            console.log(data)
            let quote = data.quoteText
            let author = data.quoteAuthor === '' ? 'Unknown': data.quoteAuthor

            //Slide animation
            $("#content").slideUp(500, function(){
                $("#text").html(``)
                $("#author").html(``)
            })
            $("#content").fadeOut(500, function(){
                $("#text").html(`${quote}`)
                $("#author").html(`${author}`)
            })

            $("#content").slideDown(500, function(){
                //Hide loading spinner after content finished sliding down
                $("#loadingSpinner").hide()
            })
            $("#content").fadeIn(100)

            //Set share links
            const twitLink = `https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=${quote} --- ${author}`
            const tumblrLink = `https://www.tumblr.com/widgets/share/tool?posttype=quote&tags=quotes,freecodecamp&caption=${author}&content= ${quote}&canonicalUrl=https%3A%2F%2Fwww.tumblr.com%2Fbuttons&shareSource=tumblr_share_button`
            $("#tweet-quote").attr('href',twitLink)
            $("#tumblr-quote").attr('href', tumblrLink)
        },  
        type: 'GET'
    });

}

$(document).ready(function(){
    //Enable button tooltip
    $(function () {
        $('[data-toggle="tooltip"]').tooltip()
    })

    //Initally hide the loading spinner
    $("#loadingSpinner").hide()

    //First Load
    switchQuote();

    //Trigger fetch of new quote
    $("#new-quote").click(switchQuote);

});
              
            
!
999px

Console