Java Reference
In-Depth Information
Because the event listener is attached to the form, we can use the
target
property to
identify which button was clicked. The
value
property corresponds to the answer given
by the player, so this is given as an argument to the
check()
function, which will check
to see if this is the correct answer.
In the
check()
function, the following line should be changed:
if(answer === quiz.questions[i].answer){
It needs to be modified as the question that was asked is now stored in the
question
variable, so we only need to check its
answer
property as follows:
if(answer === question.answer){
Since we are no longer using the variable
i
to keep track of the question being asked, we
can also remove this line from the
check()
function:
i++;
Our last task is to remove the input and submit button from the form in the index.htm file
as these are no longer used, so our form should look like this:
<form id="answer">
</form>
Have a go at playing the game by opening index.htm in a browser. The quiz now has a very
different feel to it, and should look a little like the screenshot shown in
Figure 11.1
.
