cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div class="flexbox">
  <div class="quoteBox">
    <div class="quotesArea">
      <p class="text-center intro"><strong>Push the button and get a quote!</strong></p>
    </div>
    <div class="buttons flexbox">
      <a href="#" id="link" target="_blank"><button class="btn btn-primary" id="twitterQuote" type="submit">Tweet this!</button></a>
      <button class="btn btn-primary" id="nextQuote" type="submit">Next Quote</button>
    </div>
  </div>
</div>
            
          
!
            
              /* Make everything prettier */

html,
body {
  margin: 0;
  height: 100%;
}

.flexbox {
  display: flex;
  justify-content: center;
  align-items: center;
  height: inherit;
}

.quoteBox {
  background-color: #eee;
  width: 600px;
  height: 300px;
  border: 1px solid #000;
}

.quotesArea {
  height: 75%;
}

.quotes {
  padding-top: 30px;
}

.buttons {
  height: 25%;
  justify-content: space-around;
}

.intro {
  padding-top: 60px;
}
            
          
!
            
              //Important Note: for proper use with this API make sure you prefix your URL with 'http' instead of 'https'

//Missing 1: only request quotes with less than or equal to 140 characters (since Twitter prohibits > 140) OR write a function that cuts the sentence off after 137 characters and adds "..." (actually already done in the "Basic Algorithm" section on FCC)

//Missing 2: When hitting the tweet button, not only the content but also the author's name should be transferred

$(document).ready(function() {
  $('#nextQuote').on('click', function() {
    $.ajax({
      type: 'GET',

      url: 'https://cors-anywhere.herokuapp.com/https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1',

      success: function(data) {
        var quote = {
          //Is it okay to already capitalize the properties here for later use in the p-elements as text (see for loop)?
          Author: data[0].title,
          Quote: data[0].content.slice(3, data[0].content.lastIndexOf(".") + 1)
          //Cutting out the p-tags and the carriage return space
        };
        //console.log(quote);
        var html = "<div class='quotes text-center'>";

        for (var prop in quote) {
          html += "<p><strong>" + prop.toString() + "</strong></p>";
          html += "<p>" + quote[prop] + "</p>";
        }
        html += "</div>";
        console.log(html);

        $(".quotesArea").html(html);
      },
      error: function() {

      },
      cache: false,
    });
  });
  $('#twitterQuote').on('click', function() {
    var tweet = $('p:last-of-type').text().split(" ").join("%20");
    //Get the quote without using a global variable. Any more eloquent ideas?
    $("#link").attr("href", "https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=" + '"' + tweet + '"');
    //console.log(tweet);
  });
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console