vendredi 21 août 2015

How to increment randomly in Javascript? [duplicate]

This question already has an answer here:

I have an array like this

var questions = [

["Taxonomy is the __________ of organisms.","structure","classification","dissecting","opening","B"],

["How many charactersitics do all living things have in common?", "7","4","6","3","A"],

["Which of the following is not a taxanomic classifcation?", "kingdom", "height", "phyla","class","B"],
];

Each question and answer is randomly picked from the array and displayed on the page in a div via a function called renderquestion(); and the variable random is passed as an argument.

Now each answer is rendered as a button with a onclick function which is suppose to renders another random question and answer out of the total array. Like sore of increment randomly.

now the function on the button looks like this

function next() {

question++;

renderQuestions();

}

but that just displays NAN, I tried this

   function next() {

   renderQuestions();

}

It just doesn't display a next question randomly out of the array of questions it just does nothing. How can I get another random question and answer from the array to be rendered when the button is pressed without repeating the same question?




Aucun commentaire:

Enregistrer un commentaire