Java Reference
In-Depth Information
// increase score by 1
score++;
} else {
alert("Wrong!");
}
}
An if ... else block is then used, depending on whether the answer is right or wrong.
If it is right, then an alert dialog is shown saying that it is correct and the score is incremen-
ted by 1, using score++ . Otherwise, if the answer is wrong, an alert dialog informs the
player.
When the loop has finished iterating through each question in the questions array, we
finish by using another alert dialog to inform the player that the game is over and tell them
how many questions they answered correctly:
scripts.js (excerpt)
alert("Game Over, you scored " + score + " points");
Have a go at playing the quiz in your browser by opening the index.htm file. It should look
like the screenshot shown in Figure 3.8 .
Search WWH ::




Custom Search