Java Reference
In-Depth Information
The ask() function also needs updating, so that it provides a number of options for the
player to select instead of just an input field for the player to fill in. This makes the ask()
function quite a bit longer than it was before. It needs to be changed as follows:
function ask(question) {
console.log("ask() invoked");
// set the question.asked property to true so it's not
asked again
question.asked = true;
update($form,quiz.question + question.question + "?");
// create an array to put the different options in and a
var options = [], button;
var option1 = chooseOption();
var option2 = chooseOption();
// add the actual answer at a random place in the
options array
// loop through each option and display it as a button
options.forEach(function(name) {
button = document.createElement("button");
button.value = name;
button.textContent = name;
// choose an option from all the possible answers but
choosing the same option twice
function chooseOption() {
var option =
quiz.questions[random(quiz.questions.length) - 1];
// check to see if the option chosen is the current
question or
already one of the options, if it is then recursively
Search WWH ::

Custom Search