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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <main id="quote-box" class="content">
  <div id="display">
    <blockquote id="quote">
      <div id="text">The place God calls you to is the place where your deep gladness and the world’s deep hunger meet.</div>
      <footer id="author">— Frederick Buechner</footer>
    </blockquote>
  </div>
  <div id="panel" class="buttons">
    <a id="tweet-quote"
      class="start button"
      href="https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=%22The%20place%20God%20calls%20you%20to%20is%20the%20place%20where%20your%20deep%20gladness%20and%20the%20world%E2%80%99s%20deep%20hunger%20meet.%22%20%E2%80%94%20Frederick%20Buechner"
      target="_blank"
      value="tweet"
      data-key="ArrowLeft"
      data-keycode="37">Tweet</a>
    <a id="new-quote"
      class="reset button"
      value="new-quote"
      data-key="ArrowRight"
      data-keycode="39">New Quote</a>
  </div>
</main>

              
            
!

CSS

              
                /*
====================================

Random Quote Machine CSS

====================================
*/

body {
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  font-size: 100%;
  font-family: Helvetica, sans-serif;
  vertical-align: baseline;
}

a {
  text-decoration: none;
}

/*
------------------------------------
Display
------------------------------------ */

#display {
  font-weight: normal;
  font-size: 1.4em;
  text-align: center;
  margin: 0;
  padding: .5em;
  position: absolute;
  width: 100%;
  height: 90%;
  top: 0;
  right: 0;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

#quote {
  position: relative;
  top: -3em;
  -webkit-font-smoothing: antialiased;
  -moz-font-smoothing: antialiased;
  -o-font-smoothing: antialiased;
}

#quote::before {
  content: '‘‘';
  font-size: 6em;
  font-weight: bold;
  letter-spacing: -0.07em;
  color: #fff;
  color: rgba(255,255,255,.15);
  position: relative;
  top: .5em;
}

#author {
  font-size: .6em;
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-top: 2em;
  color: #fff;
  color: rgba(255,255,255,.5);
}

/*
------------------------------------
Buttons
------------------------------------ */

#panel {
  position: absolute;
  top: 90%;
  left: 0;
  width: 100%;
  height: 10%;
}

.button {
  font-size: 1.2em;
  text-align: center;
  display: block;
  width: 50%;
  height: 100%;
  position: absolute;
  margin: 0;
  padding: .5em .75em;
  border-radius: 0;
  box-sizing: border-box;
  -webkit-appearance: none;
  -moz-appearance: none;
  -webkit-font-smoothing: antialiased;
  -moz-font-smoothing: antialiased;
  -o-font-smoothing: antialiased;
  display: flex;
  align-items: center;
  justify-content: center;
}

#new-quote {
  top: 0;
  left: 50%;
}

#tweet-quote {
  top: 0;
  left: 0;
}

/*
------------------------------------
Color
------------------------------------ */

#display {
  color: #fff;
  background: #000;
}

.button {
  color: #fff;
  background: #444;
  border: 1px solid #000;
}

.button:hover {
  background: #333;
}

.button.select,
.button:active {
  background: #222;
}

.button:focus {
  outline: 0;
}


/*
------------------------------------
Media Queries
------------------------------------ */

@media (min-width: 600px) and (orientation: portrait) {

  #display {
    font-size: 2em;
  }

  .button {
    font-size: 1.6em;
  }

}

@media (max-width: 750px) and (orientation: landscape) {

  #panel {
    top: 80%;
    height: 20%;
  }

}

@media (min-width: 750px) {

  #display {
    font-size: 2.4em;
  }

  #quote {
    max-width: 750px;
    margin: 0 auto;
  }

  .button {
    font-size: 2em;
  }

}

              
            
!

JS

              
                /*--------------------------------*/
/* Random Quote Machine           */
/*--------------------------------*/
/* by Stephen Bau                 */
/*--------------------------------*/

var display = document.getElementById("display");
var buttons = document.getElementsByClassName("button");
var tweetButton = document.getElementById("tweet-quote");
var quoteButton = document.getElementById("new-quote");
var dataURL = "https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json";
var quotesJSON = null;
var quotes = [];
var quote = {
  num: 1,
  text: null,
  author: null
};
var colors = ['#16a085', '#27ae60', '#2c3e50', '#f39c12', '#e74c3c', '#9b59b6', '#FB6964', '#342224', "#472E32", "#BDBB99", "#77B1A9", "#73A857"];
var color = {
  id: 0,
  hex: colors[0]
};
var tweet = {
  root: "https://twitter.com/",
  path: "intent/tweet",
  query: {
    hashtags: "quotes",
    related: "freecodecamp",
    text: ""
  }
}
var tweetURL = "";
var displayText = document.getElementById("text");
var displayAuthor = document.getElementById("author");

var key = {id: null, name: null, code: null};

init();

function init() {
  getJSON(dataURL, getQuotes);
  for (var i = 0; i < buttons.length; i++) {
    var button = buttons[i];
    button.addEventListener("click", function( event ) {
      getInput(this, "click");
    });
  }
  keyboard();
}

function getQuotes(data) {
  quotesJSON = parseJSON(data);
  quotes = quotesJSON.quotes;
  getRandomQuote(quotes);
}

function getRandomQuote() {
  var num = randomNumber(quote.num, quotes.length);
  getCurrentQuote(num);
}

function getCurrentQuote(num) {
  quote.num = num;
  quote.text = quotes[num].quote;
  quote.author = quotes[num].author;
  displayCurrentQuote();
  changeBackground();
  setTweetQuoteURL();
}

function displayCurrentQuote() {
  displayText.innerText = quote.text;
  displayAuthor.innerText = "— " + quote.author;
}

function changeBackground() {
  color.id = randomNumber(color, colors.length);
  color.hex = colors[color.id];
  display.style.background = color.hex;
}

function setTweetQuoteURL() {
  var tweetTextURI = encodeURIComponent('"' + quote.text + '" — ' + quote.author);
  tweetURL = tweet.root
    + tweet.path
    + "?" + "hashtags=" + tweet.query.hashtags
    + "&" + "related=" + tweet.query.related
    + "&" + "text=" + tweetTextURI;
  tweetButton.setAttribute('href', tweetURL);
}

function openTweetURL() {
  window.open(tweetURL);
}

function getInput(button, eventType) {
  key.id = button.id;
  key.name = button.dataset.key;
  key.code = button.dataset.keycode;

  if (key.id == "new-quote") {
    getRandomQuote();
  }

  if (key.id == "tweet-quote" && eventType == "keyboard") {
    openTweetURL();
  }
}

function keyboard() {
  keyboardEvents("keydown");
  keyboardEvents("keyup");
}

function keyboardEvents(keyEvent) {
  document.addEventListener(keyEvent, function (event) {
    if (event.defaultPrevented) {
      return;
    }
    for (var i = 0; i < buttons.length; i++) {
      var button = buttons[i];
      if (button.dataset.key == event.key || button.dataset.keycode == event.keyCode) {
        if (keyEvent == "keydown") {
          button.classList.add("select");
          getInput(button, "keyboard");
        }
        if (keyEvent == "keyup") {
          button.classList.remove("select");
        }
      }
    }
  });
}

function getJSON(url, func) {
  loadFile(url, 2000, loadJSON, func);
}

function loadJSON(func) {
  var data = this.responseText;
  func(data);
}

function parseJSON(text) {
  if (text) {
    return JSON.parse(text);
  }
  return null;
}

function loadFile(url, timeout, callback) {
  var args = Array.prototype.slice.call(arguments, 3);
  var xhr = new XMLHttpRequest();
  xhr.ontimeout = function () {
    console.error("The request for " + url + " timed out.");
  };
  xhr.onload = function() {
    if (xhr.readyState === 4) {
      if (xhr.status === 200) {
        callback.apply(xhr, args);
      } else {
        console.error(xhr.statusText);
      }
    }
  };
  xhr.open("GET", url, true);
  xhr.timeout = timeout;
  xhr.send(null);
}

function randomNumber(current, num) {
  var num = Math.floor(Math.random() * num);
  if (current == num) {
    return randomNumber(current, num);
  } else {
    return num;
  }
}

              
            
!
999px

Console