css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html lang = "en">
  <head>
    <!-- external links to the fonts -->
      <link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">

      <title>Random Quotes</title>
    <head>  
    <body>
      <div class="opacity-div">
      <!-- quote generator output -->
      <div class = "container-fluid">
        <div class = "row" id ="quote-area">

          <div class = "col-md-12">
            <p class="text-center quote-of-day"> Quote of the day
            </p>
            <div id="quoteGeneratedArea">
              <p class ="quote-text"> Quote
              </p> 
              </br>
              <p class="quote-author"> Quote Author
             </p>  
           </div> 
          </div>

        </div> 
     </div>   
     <div class ="container-fluid">   
        <div class ="row" id ="social-area">
          <div class ="col-md-2">
            <a href="https://twitter.com/" target="_blank" class="blue-twitter"><i class="fa fa-twitter" aria-hidden="true"></i>
            </a>
          </div>
          <div class ="col-md-8">
          </div>
          <div class ="col-md-2"><button type ="button" class ="btn btn-warning" id="next-button">Next Quote</button>
          </div>
        <div>  
      </div> 
     </div>      
  </body>  
</html>  
            
          
!
            
              body{
  background-color: #B30E45;
}

#quote-area{
  margin: 100px 150px 0px 150px;
  padding-bottom: 0px;
  min-height: 250px;
  border-color: black;
  border-style: solid;
  border-width: 5px;
  background-color: white;
}

/*-- styling the quote of the day --*/
.quote-of-day{
  font-family: lobster;
  font-size: 20px;  
  padding: 10px;
  color: #fbc97f;
  text-shadow: 0.5px 0.5px orange;
}

/*-- styling the quote itself --*/
p{
  font-family: lobster;
}
.quote-text{
  font-size: 50px;
}
.quote-author{
  font-size: 25px;
  text-align: right;
}

/*--- styling the social section --*/
#social-area{
  margin: 0px 150px 100px 150px;
  min-height: 50px;
  border-color: black;
  border-style: solid;
  border-width: 5px;
  background-color: white;
}

.blue-twitter{
  font-size: 25px;
}
            
          
!
            
              // when the document loads 

$(document).ready(function(){
  // defining local variable to 
  var key = Math.floor(Math.random() * 10000 + 1);
  var url ='https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&Key='+ key +'&jsonp=?';
  
//var url ='https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&Key='+ key +'&jsonp=?';


    
  /* there was scope issue so I had to put this function outside the document ready function if i  use callback randomGenerateQuote within the url if not I can use it inside the document ready function for eg this $.getJSON('https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&Key='+ key +'&jsonp=', function (data){
    console.log(data);
  }); */
  
function randomGenerateQuote(data){
    var QuoteGenerated = data.quoteText;
    var QuoteAuthor = data.quoteAuthor;
    
    $('.quote-text').text('"'+QuoteGenerated);     
   
    if (QuoteAuthor !== ''){
       $('.quote-author').text(' -'+QuoteAuthor);
    } else {
      $('.quote-author').text(' -Anonymous');
    }    
}
  
// to display the quote when the page loads
$.getJSON(url,randomGenerateQuote);
  
// add onclick method to the button to generate next quote
$('#next-button').on("click", function(){
  $.getJSON(url, randomGenerateQuote) 
  }); 
});

/* Note to self 

or some reason is jsonp="a specific function name" . it doesnt see the function if it's inside the ,ready
@IndiraShrestha but if you change it to jsonp=? instead you can put it anywhere(or just use anonymous function)

$.getJSON('https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&Key='+ key +'&jsonp=?', function(data){console.log(data)});



$(document).ready(function(){
  var key = Math.floor(Math.random() * 10000 + 1);

  function randomGenerateQuote(data){
    var QuoteGenerated = data.quoteText;
    var QuoteAuthor = data.quoteAuthor;
    $('.quote-text').text(QuoteGenerated);
    $('.quote-author').text(QuoteAuthor);
  }

  $.getJSON('https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&Key='+ key +'&jsonp=?', randomGenerateQuote);

});

*/

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console