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

              
                <head>
  <h1 class="text-center">Random Quote Generator</h1>
</head>

<body>
  
  <div id="main" class="container well">
    <div id="quote-box" class="text-center">
      <span id="quote" class="author">Click below for a new quote.</span>
    </div>
    <div id="button" class="row text-center">
      <div id="tweet" class="col-xs-6">
        <button class="btn fa fa-twitter share-quote">Share quote</button>
      </div>
      <div id="share-quote" class="col-xs-6">
        <button class="get-quote btn">New quote</button>
      </div>
    </div>
  </div>
</body>
              
            
!

CSS

              
                body{
  background-color:black;
  color: white;
  font-family: "Times New Roman";
}

#quote-box{
  font-size: 20px;
  color:black;
  margin-bottom: 50px;
  font-weight: bold;
  font-style: italic;
}


#main{
  width:540px;
}

button{
  color:black;
}
              
            
!

JS

              
                /*to do
*1. Get new quote function
*2. Share via twitter function
*/

$(document).ready(function() {
  //function to get a new quote from the Forismatic API. Learnt from a Stephen Mayeaux video on YouTube-https://www.youtube.com/watch?v=5xeDQ1-ZfcQ
  function getNewQuote(){
	//jQuery function to make the API request
    $.ajax({
		//Passes the URL for the API request through a PROXY-a resource error was coming up in the console
      url:"https://cors-anywhere.herokuapp.com/https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en",
		//If the API request is successful, allocate the quote and it's author to the relevant variables.
      success: function(response){
			quote = response.quoteText;
			author = response.quoteAuthor;		//Some quotes have no author, so populate unkown for those occcasiona
			if(author){
        $('#quote').html(quote + ' - ' + author);
      }
      else{
        $('#quote').html(quote + ' - ' + 'unknown');
      }
		}	
	});
}
//Allocate get quote to the new quote button.
$('.get-quote').click(function() {
  getNewQuote();
});

//Open a new window with a Tweet box already there with the quote in.
$('.share-quote').click(function(){
  window.open('https://twitter.com/intent/tweet?text=' + encodeURIComponent(quote + ' -- ' + author));
});  

});

              
            
!
999px

Console