Information Technology Reference
In-Depth Information
Twitter accounts that we will use
to pull in random tweets for each
round
*/
var defaultIcon =
' https://si0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png';
var currentRound = [];
var correct = '';
var tweets = [
'jimmyjohns',
'sugarsammyk',
'wilw',
'JeriLRyan',
'pattonoswalt',
'trutriciahelfer',
'AndrewWK',
'ChristianKane01',
'charliesheen',
'levarburton',
'edwardjolmos',
'Rosie',
'kevinrose',
'jason',
'leolaporte',
'aplusk',
'StacyKeibler',
'LilianGarcia',
'nicolerichie',
'rainnwilson',
'ericschmidt',
'pennjillette',
'nerdist',
'Scobleizer'
];
Here we define a few global variables that will be used throughout the application. The
first being the defaultIcon variable which contains a long URL for the image of the
default user Twitter avatar we will be using throughout the script. We could have done
without the variable and just added the code to our script when we needed it but it is
always good practice when coding to cache as much of your code for reuse as possible.
Now when we want to add the defaultIcon anywhere in our script, we do not have to
remember some big long complicated URL that in most cases will just visually muck up
our code.
Next we create an empty array called currentRound which will house all of the data we
pull in from Twitter for the round we are on. We create a predefined array of verified
users to randomly choose from. For this list, I just did a Google search for verified
Twitter users and copied the names of all the users I found on the first page of the
Google search.
If this were a real game based off of the Twitter API and not a demo, we would want to
utilize an online server with a list of all Twitter verified accounts but, since we are starting
small, an array will work just fine for now.
Listing 2-6 shows the second part of the main JavScript file for Who's That Tweet.
Search WWH ::




Custom Search