Javascript global variable doesn't seem to be incrementing?

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:

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 index++:

$("#tweet").attr("href", "" + encodeURIComponent('"' + quotes[index] + '" ' + authors[index]));
1 Like

Ahhh I see! Thank you, that fixed it!