dimanche 27 septembre 2015

How do i randomly display my questions so its now always the same? (JavaScript)

<script type="text/javascript">

var questions = [
    ['http://ift.tt/1GaXDgH','0'],
    ['http://ift.tt/1NVKOgH','1'],
    ['http://ift.tt/1GaXDgJ','2'],
    ['http://ift.tt/1FC1p7V','3'],
    ['http://ift.tt/1LVZLef','4'],
    ['http://ift.tt/1FC1nN6','5'],
    ['http://ift.tt/1LVZLeh','6'],
    ['http://ift.tt/1FC1p7Z','7'],
    ['http://ift.tt/1FC1pod','8'],
    ['http://ift.tt/1LVZIPE','9'],
    ['http://ift.tt/1FC1nN9','10'],
    ['http://ift.tt/1LVZLuw','11'],
    ['http://ift.tt/1FC1nNb','12'],
    ['http://ift.tt/1LVZJ5S','13'],
    ['http://ift.tt/1FC1nNd','14'],
    ['http://ift.tt/1LVZLuy','15'],
    ['http://ift.tt/1FC1pof','16']
];
var qNo = 0;
var correct = 0;
var cnt = 0;

function NextQuestion(response) {
  if ((qNo < questions.length) && (response == questions[qNo][1])) { correct++; }
  document.getElementById('score').innerHTML 
    = 'Your score is '+correct+'/'+(cnt+1);
  qNo++;
  if (qNo < questions.length) { document.getElementById('Pic').src = questions[qNo][0]; cnt++; }
                     else { alert('Quiz is done'); }
}
onload = function() {
 document.getElementById('Pic').src = questions[0][0];
}

</script>

Okay so basically I have 17 questions and 17 answers that are listed using the numbers 0-16, what I want to do is randomize the order in which the pictures are shown so that you cant just find a pattern and not answer it right, also and I cant figure this out, I want to make it so that after each question is answered a green Correct or a Red incorrect shows up depending on If you got the previous question right can anyone help?




Aucun commentaire:

Enregistrer un commentaire