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.

            
              
<body>
  <div class="quote_box">
    
    <div class="quote_text">
      <p><i class="fa fa-quote-left" aria-hidden="true"></i></p>
      <span id="text"></span>
      <div class="load"><i class="fa fa-spinner fa-spin"></i></div>
      <p><i class="fa fa-quote-right" aria-hidden="true"></i></p>
    </div>
      
    <div class="quote_author">
    - <span id="author"></span>
    </div>
      
    <div class="buttons">
    <button class="button" id="tweet-quote" title="Tweet this quote!" target="_blank">
      <i class="fa fa-twitter"></i>
    </button>
    <button class="button" id="new-quote">New quote</button>
  </div>
      
    </div>
          
        
   
  <div class="footer"> by <a href="https://forismatic.com/en/">forismatic</a></div>
  
</body>
            
          
!
            
              div{
  position:relative;
  }
body{
  font-family:sans-serif;
  font-weight:400;
  background-color:#333;
  }
.quote_box{
  border-radius:3px;
  background-color:#fff;
  margin:8% auto auto auto;
  padding:40px 50px;
  width:450px;
}
.quote_text{
  text-align:center;
  width:450px;
  height:auto;
  clear:both;
  font-weight:500;
  font-size:1.75em; 
}
.quote_text i{
    font-size:2.0em;
    margin-right: 0.4em;
  }

.quote_author{
  clear:both;
  padding-top:6px;
  font-size:1em; 
  text-align:right;
 
}
.buttons{
  margin:auto;
  display:block;
  
}
.buttons .button{
  height:38px;
  border:none;
  border-radius:3px;
  color:#fff;
  background-color:#333;
  outline:none;
  font-size:0.85em;
  padding: 8px 18px 6px 18px;
  margin-top:30px;
  opacity:1;
  cursor:pointer;
  &:hover {
      opacity:0.4;
  }
}
#new-quote{
  float:right;
}
.footer{
  margin:15px auto 30px auto;
  text-align:center;
  display:block;
  font-size:1.0em;
  color:#fff;
}
.footer a{
  color:#fff;
  font-weight:600;
  text-decoration:none;
}
            
          
!
            
              var colors = ['16a085', '27ae60', '2c3e50', 'f39c12', 'e74c3c', '9b59b6', 'FB6964', '342224', "472E32", "BDBB99", "77B1A9", "73A857"];

//for tweet-button
function tweet(message) {
  window.open('https://twitter.com/intent/tweet?hashtags= freecodecamp&text='   + encodeURIComponent(message));
}
var msg;
function tweetHandler() {
  tweet($(msg).text()); 
  //tweet(msg);
}



$(document).ready(function() {
  // Hide the empty quote_box and show the loading
  // icon as we request another quote.
  $('#text').show();
  $('.quote_author').show();
  $('.load').hide();
  getQuote();
  //generate random background colors even befor click
   var color = Math.floor(Math.random() * colors.length);
   $('body, .button').css('background', '#' + colors[color]);
   $('.quote_text, .quote_author').css('color', '#' + colors[color]); 
    
  $('#tweet-quote').on('click', tweetHandler);// button to tweet out a quote
  
  // Do the same as above when the button is clicked.
  $('#new-quote').on('click', function(){
    getQuote();
    $('#text').hide();
    $('.quote_author').hide();
    $('.load').show();
   
  //generate random background colors on click
   var color = Math.floor(Math.random() * colors.length);
   $('body, .button').css('background', '#' + colors[color]);
   $('.quote_text, .quote_author').css('color', '#' + colors[color]);   
      
  });

});

//our AJAX getQuote function
var getQuote = function(){  
  $.ajax({
    url: 'https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=?',
    dataType: 'jsonp',
    // If the request is successful
    success: function (data){
      console.log(data);
      
      
      // Hide the loading icon
      $('.load').hide();
      // Show the text and author element
      $('#text').show();
      $('.quote_author').show();
      // Add the quote to the #quoteText element
      $('#text').html(data.quoteText);
      if (data.quote_author !== ''){
        // If there is an author
        $('.quote_author').html(data.quoteAuthor);
      }
      else{
        // When there is no author
        $('.quote_author').html('Unknown');
      }
    },
    
    // Set up a way to gracefully handle errors
    error: function (xhr, status, error){
      $('#text').text('I\'m not sure what happened there. Click again and let\'s see if that does the trick!');
      $('.quote_author').text('Your Trusty Browser');
    }
    
  
  });
};
            
          
!
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