Need help with my Quote Machine

Need help with my Quote Machine
0.0 0

#1

The quote machine challenge with a tweet button. I have been going insane trying to get this to work struggling for the past 3 days. I’m at my wits end. Somebody please tell me what the hell I’m doing so wrong to be so bad at this. https://codepen.io/Jobo_v22/pen/vdeXEL?editors=1010

The quote machine is fine and functional, but for the love of god, this damn twitter share button has be almost in tears, yelling at my computer screen and hating my life. I’ve been looking god damned EVERYWHERE for answers and all the answers I find work perfectly in the video/tutorial/guide as soon as I use it god damn character for character it does absolutely nothing close to work.


#2

Hi @MeatyJobo

I’d directly update the href attribute of the link tag from within the newQuote function, rather than relying on the window.open function. That way you also have direct access to the quote variables when you create them, rather than pulling them from the DOM.

Something like this perhaps if your stuck:

function newQuote(){
  var rndNum = Math.floor(Math.random()*quote.length);
  var quot = quote[rndNum];
  var auth = author[rndNum];
  var fullQuote = quot + auth;
  var twitLink = "https://twitter.com/intent/tweet?text=" + fullQuote;
  
  if (fullQuote.length > 280) {
    twitLink = "https://twitter.com/?status=I+just+found+a+%23meaty+%23quote,+but+it's+too+long+%23to+share+with+you+all,+%23sucksforyou.+Get+your+own+at+https://codepen.io/Jobo_v22/full/vdeXEL/"
  }
  
  document.getElementById('quoteDisplay').innerHTML = quot;
  document.getElementById('authorDisplay').innerHTML= auth;
  document.getElementById('twitterButton').setAttribute("href", twitLink);
};

newQuote();

#3

Holy hell thank you so much, can’t even describe how happy I am now that it’s working, you are a life saver!!