JSFiddle - React, Tailwind, and code Playground

by nabtron

HTML

<p>
<a href="#" id="tweet">
tweet
</a>
 and 
<a href="#" id="newQuote">
newQuote
</a>
</p>
<p>
<span class="quote"></span>
<br>
<span class="author"></span>
</p>

JavaScript

$(document).ready(function(){

  var randQuote;
  var randAuthor;
  var randNum;



  function getQuote(){
    var quote =["While you are destroying your mind watching the worthless,     brain-rotting drivel on TV, we on the Internet are exchanging, freely and openly, the most uninhibited, intimate and, yes, shocking details about our config.sys settings", "The secret of getting ahead is getting started.", "The unforgivable crime is soft hitting.  Do not hit at all if it can be avoided; but never hit softly.", "The man on the top of the mountain didn't fall there.", "You can avoid most of the sorrows of life, the only requirement being that you avoid all the happiness."];
    var author =["-Dave Barry", "-Mark Twain", "-Theodore Roosevelt","-Vince Lombardi", "-Robert Brault"];
 var randNum = Math.floor(Math.random()*quote.length);
 randQuote = quote[randNum];
 randAuthor = author[randNum];
$(".quote").text(randQuote);
$(".author").text(randAuthor);
  }

  $("#newQuote").on("click", function(){
  getQuote();    
  });


  $("#tweet").on("click", function(){
    var tweetQuote = randQuote;
    var currentLength = randQuote.length + randAuthor.length + 1;
  if(currentLength > 140){
  var oneforty = 139 - randAuthor.length ; // 140 minus the space
  tweetQuote = tweetQuote.slice(0, oneforty);
}
 window.open("https://twitter.com/intent/tweet?text=" + encodeURIComponent(tweetQuote) + " " +   encodeURIComponent(randAuthor));
  })

});