HTML and CSS Reference
In-Depth Information
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
<html>
Starting
html
tag
<head>
Starting
head
tag
<title>Quiz</title>
Complete
title
element
<style>
Start of
style
section
.thing {position:absolute;left: 0px;
top: 0px; border: 2px;
border-style: double;
background-color: white; margin:
5px;
padding: 5px; }
A style for all elements of the class
thing
. The original
position is at the top, left corner of the window. Theres a
thick border and a white background color.
</style>
End of
style
element
<script>
Start
script
element
var facts = [
Start of declaration of the
facts
variable, array of arrays
["China","Beijing",false],
Each row is a complete array, 3 elements, country,
capital, false
The
false
field will be changed if this row is chosen to be
presented
["India","New Delhi",false],
["European Union","Brussels",false],
["United States","Washington,
DC",false],