Clean up JS code in various ways

-Change lists to have meaningful names instead of "first" and "second.
-Get rid of duplicate code in HTML generation.
-Consolidate code for getting a random array element.
-Change coding style to my current preferred style.