Random quote machine with api

In this example below you will see how to do a Random quote machine with api with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by DanielGM, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright DanielGM ©
  • HTML
  • CSS
  • JavaScript
    <div class="container">
  <h1> RANDOM QUOTE MACHINE </h1>
  <div class="quoteAll">
  <div class="quoteText">
  <span class = "quote"></span>
  </div>
      <br/>
  <div class="quoteAuthor">
    <p id = "author" class="author"></p>
  </div>
  <br/>
    <div class="buttons">
  <button class="btn btn-primary" id="tweet" type="submit">Tweet it!</button>
  <button class="btn btn-success" id="new" type="submit">New quote</button>
    </div>
  </div>
</div>

/*Downloaded from https://www.codeseek.co/DanielGM/random-quote-machine-with-api-JRWQAJ */
    body{
  text-align:center;
  background-color:#66ffff;
}
h1{
  font-family:lobster;
}
.quoteAll{
  background-color: #00b300;
  border-radius:20px;
  /*height:220px;
  width:600px;*/
  margin-right:auto;
  margin-left:auto;
}
.quoteText{
  padding-top:20px;
  /*width:80%;*/
  margin-right:auto;
  margin-left:auto;
  font-size:1.8em
}
.quoteAuthor {
    width:78%;
    text-align:right;
    font-style:oblique;
  }
.buttons{
  padding-bottom:20px;



/*Downloaded from https://www.codeseek.co/DanielGM/random-quote-machine-with-api-JRWQAJ */
    $(document).ready(function(){
  var tweetQuote;
  newQuote();
  console.log('asd');
  function newQuote(){
    $.getJSON("https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?", function(data){
      console.log(data);
    $(".quote").html('"'+data.quoteText+'"');
    $(".author").html('-'+data.quoteAuthor);
      tweetQuote=data.quoteText;
  });
  };
  $("#new").click(function(){
    newQuote();
  })
  $("#tweet").click(function(){
    window.open("https://twitter.com/intent/tweet?text=" + tweetQuote);
  })
})

Comments