When you declare twitterUrl within the $(document).ready callback function it is local to this callback function and is not part of the global scope (where your newQuote function is defined). So, the twitterUrl inside newQuote is not the same as the one in the $(document).ready callback funciton. hat the but do not set it to a value, so JavaScript assigns it the value undefined by default. One way to fix this, is by to move the newQuote function inside the $(document).ready callback function.
You have some other issues with your code related to the building of twitterURL, but that you can see what is being displayed in the alert, you should be able to resolve.