Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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 class="container-fluid">
  <div class="wrapper">
    <h1>Thus wrote the Bard...</h1>
    <div class="centered">
      <div>
        <p id="printQuote"></p>
        <p id="author">- William Shakespeare</p></div>
      <div><img id="button" onclick="generateQuote();" src="https://res.cloudinary.com/kokkieh/image/upload/v1442167532/Shakespeare%20Quote%20generator/quill.png" onmouseover="this.src='https://res.cloudinary.com/kokkieh/image/upload/v1442167532/Shakespeare%20Quote%20generator/quill2.png'" onmouseout="this.src='https://res.cloudinary.com/kokkieh/image/upload/v1442167532/Shakespeare%20Quote%20generator/quill.png'"></div>
    </div> <!--Close centered-->
    <div class="push"></div>
  </div> <!--Close wrapper-->
  <div class="footer">Powered by the STANDS4 Web Services <a href="http://www.quotes.net/quotes_api.php">Quotes API</a></div>
</body>
              
            
!

CSS

              
                body {
  height: 100vh;
  text-align: center;
  background: fixed center no-repeat url( "https://res.cloudinary.com/kokkieh/image/upload/a_180/v1442164901/Shakespeare%20Quote%20generator/scroll_background.jpg") #cbb385;
  background-size: 100% 100%;
}
.wrapper {
  min-height: 100vh;
  height: auto !important;
  height: 100vh;
  margin: 0 auto -3em; 
  padding: 1em;
}
.footer, .push {
  height: 3em; 
}
/*
Sticky Footer by Ryan Fait
http://ryanfait.com/
*/
.footer {
  padding: 1em;
  background-color: rgba(203,179,133,0.7);
  font-size: 1.5vmin;
}
h1 {
  font-family: 'Italianno', Brush Script MT, cursive;
  font-size: 9vmin;
  margin-top: 1em;
  margin-bottom: 5rem;
}
.centered {
  width: 100%;
  max-width: 70vmax;
  margin: auto;
}
#printQuote {
  font-family: 'Italianno', Brush Script MT, cursive;
  font-size: 4vmin;
}
#author {
  font-family: 'Italianno', Brush Script MT, cursive;
  font-size: 3vmin;
}
#button {
  cursor: pointer;
}
              
            
!

JS

              
                var quote, //Stores value of randomly selected quote
    prevQuote, //Stores index of previous quote used
    val, //Stores total length of XML data
    response; //Stores XML data retrieved from API   

function randomNumber(val) { //Generates random value between 0 and length of XML data
  return Math.floor(Math.random() * val);
}

(function() { //Fetches XML data from API and prints random first quote
  var url =  /*
    * You can
    * apply for your own free key to use this API
    * at http://www.abbreviations.com/api.php
    * Thanks. 
    */
    "https://www.stands4.com/services/v2/quotes.php?uid={stands4_uid}&tokenid={API_key}&searchtype=AUTHOR&query=William+Shakespeare";
  var randomQuote = new XMLHttpRequest();
  randomQuote.onreadystatechange = function() {
    if (randomQuote.readyState == 4 && randomQuote.status == 200) {
      response = randomQuote.responseXML;
      val = response.getElementsByTagName('quote').length; //Gets length of XML data for random number generating
      generateQuote(); //Runs function to generate first quote once API call completes
    }
  }
  randomQuote.open("GET", url, true);
  randomQuote.send();
}) ();

function generateQuote() {      
  var random = randomNumber(val);
  if (random === prevQuote && random === quoteList.length-1) { 
    random--;
  } 
  else if (random === prevQuote) {
    random++;
  } //Prevents same quote being shown twice in a row
  
  quote = response.getElementsByTagName('quote')[random].firstChild.data;
  document.getElementById("printQuote").innerHTML = quote;
  
  prevQuote = random; // Saves random number for comparison to avoid repeats
}



              
            
!
999px

Console