Java Reference
In-Depth Information
question.asked = true;
update($question,this.phrase + question.question + "?");
// clear the previous options
$form.innerHTML = "";
// create an array to put the different options in and a
button
variable
var options = [], button;
var option1 = chooseOption();
options.push(option1.answer);
var option2 = chooseOption();
options.push(option2.answer);
// add the actual answer at a random place in the
options array
options.splice(random(0,2),0,this.question.answer);
// loop through each option and display it as a button
options.forEach(function(name) {
button = document.createElement("button");
button.value = name;
button.textContent = name;
$form.appendChild(button);
});
// choose an option from all the possible answers but
without
choosing the answer or 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
call this
function until it isn't
if(option === question ||
options.indexOf(option.answer)
!== -1) {
return chooseOption();
 
Search WWH ::




Custom Search