Hello all, I am making a random quote generator. My problem is with my Tweet intent button. It seems to only pre-fill the tweet box with the first quote in array quotes. The variable ‘index’ I’m using is a global variable and is incremented every time a new quote is generated so I don’t understand why it keeps acting like index is still 0. Here is my code pen link: https://codepen.io/david_vu408/pen/MJJrBv
The index variable is updating correctly.
The problem with your tweet button is that you only set its href attribute when you first load the page. You would want to update it also when you renew the quote.
So, you should put this code before the
$("#tweet").attr("href", "https://twitter.com/intent/tweet?text=" + encodeURIComponent('"' + quotes[index] + '" ' + authors[index]));
Ahhh I see! Thank you, that fixed it!