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

              
                .container
    .quotebox
        #title
            | Quote Machine
        .quote
            | "
            span#quote
            | "&nbsp;
            span#author
        #newQuote New Quote
        #tweet Tweet
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:300,400,600);
$wave-timer: 4s;
$wave-color-1: #00ccff;
$wave-color-2: #00ffcc;
@keyframes keyframes-wave-background {
    0% {
        background-color: $wave-color-1;
    }
    100% {
        background-color: $wave-color-2;
    }
}

@keyframes keyframes-wave-color {
    0% {
        color: $wave-color-1;
    }
    100% {
        color: $wave-color-2;
    }
}

@mixin wave-background {
    animation-name: keyframes-wave-background;
    animation-direction: alternate;
    animation-duration: $wave-timer;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

@mixin wave-color {
    animation-name: keyframes-wave-color;
    animation-direction: alternate;
    animation-duration: $wave-timer;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}

body {
    @include wave-background;
    font-family: 'Open Sans', sans-serif;
}

.container {
    margin: 0 auto;
    padding: 32px;
    max-width: 480px;
}

.quotebox {
    @include wave-color;
    padding: 16px;
    border-radius: 6px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
    background-color: #444444;
    color: white;
}

.quote {
    padding: 8px;
    border-radius: 2px;
    border: 2px solid #606060;
    background-color: #585858;
    min-height: 80px;
}

#title {
    text-align: center;
    font-size: 32px;
    font-weight: 300;
    margin-bottom: 16px;
}

#newQuote,
#tweet {
    margin-top: 16px;
    padding: 8px;
    text-align: center;
    border-radius: 2px;
    border: 1px solid #787878;
    background-color: #585858;
    cursor: pointer;
    user-select: none;
    &:hover {
        background: #787878;
        border: 1px solid #a8a8a8;
    }
}
              
            
!

JS

              
                var quotes = [];
var currentQuote = -1;
var tweetURL = 'https://twitter.com/intent/tweet?text=';
var encodedQuote = '';

// loading quotes from github
$.getJSON('https://raw.githubusercontent.com/davidjcastner/resources/master/free-code-camp/quote-machine/quotes.json', function(results) { quotes = results; })
    .done(function () { newQuoteHandler(); });

var getRandomInt = function(min, max) {
    // returns a integer in the range [min, max)
    return Math.floor(Math.random() * (max - min)) + min;
};

var getQuote = function() {
    // selects a random quote, making sure to avoid repeats
    if (quotes.lenght === 0) { return { text: '', author: '' }; }
    var newQuote = getRandomInt(0, quotes.length - 1);
    if (newQuote >= currentQuote) { newQuote++; } // avoids picking previous quote
    currentQuote = newQuote;
    return quotes[currentQuote];
};

var newQuoteHandler = function() {
    var quote = getQuote();
    encodedQuote = encodeURIComponent('"' + quote.text + '" ' + quote.author);
    $('#quote').text(quote.text);
    $('#author').text(quote.author);
};

$(document).ready(function() {
    $('#newQuote').click(newQuoteHandler);
    $('#tweet').click(function () { window.open(tweetURL + encodedQuote); });
});
              
            
!
999px

Console