Link to home
Start Free TrialLog in
Avatar of swet
swet

asked on

different types of questions in quizzes


Hi everyone,

I am designing a quiz using javascripts.

I have this portion of code to determine if the answer is right or wrong,

but the problem is that this code works for multiple choices questions only

I want to use this code for other tupes of question such as true & false and word completion

could anyone please help me with this

----------

var numQues = 3;
var numChoi = 4;


var answers = new Array(3);
answers[0] = "John";
answers[1] = "1995";
answers[2] = "1966";



function getScore(form) {
  var score = 0;
  var currElt;
  var currSelection;


  for (i=0; i<numQues; i++) {
    currElt = i*numChoi;
    for (j=0; j<numChoi; j++) {
      currSelection = form.elements[currElt + j];
      if (currSelection.checked) {
        if (currSelection.value == answers[i]) {
          score++;
          break;
        }
      }
    }
  }


  score = Math.round(score/numQues*100);
  form.percentage.value = score + "%";


  var correctAnswers = "";
  for (i=1; i<=numQues; i++) {
    correctAnswers += i + ". " + answers[i-1] + "\r\n";
  }
  form.solutions.value = correctAnswers;


}

---------
SOLUTION
Avatar of sathishv
sathishv

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of swet
swet

ASKER


thanks Sathish


I still have a problem in this line  

the complaint is about the word 'type' ..  I am using a textfield but Im afraid I don't understand your comment

----------

 if (currSelection.type == "text" || currSelection.checked) {   //in case a textbox is provided, it directly compares the value
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial