The Essential Guide to HTML5

(Greg DeLong) #1

CHAPTER 6


An alternative approach would be to remove a used fact from the array and to keep going until all rows
have been chosen. Look back to the use of splice in Chapter 4 for an idea of how you could achieve this.

The block for the capital is placed randomly in one of the four available slots. This produces the countries
and capital cities in two columns, but mixed up. The pickelement function does one thing if it is a first
click and another if it is a second click, determined by the value of makingmove, which starts off being
false and then is set to true at a first click.

Table 6-4 supplies a line-by-line explanation of the code.

Table 6-4. The Complete Code for the First Quiz Application

Code Explanation


Starting html tag
Starting head tag
Quiz Complete title element
End of style element