Template:Testquiz

From WikiEducator
Jump to: navigation, search

<html> <head> <title>Example Quiz 1</title> <script>

/**************************************************************************** author: Andrew Beiderman Feel free to use this code for educational/non-profit purposes only.

                                                                                                                                                        • /

//highlight color of answer - can change this color to a hex code or recognized color name var highlightColor = "#00ff00";

//this should not be changed function checkQuestionDropDown(selectGroup) {

 if (selectGroup[selectGroup.selectedIndex].value == "correct") {
    return 1;
  }
  else {
    return 0;
  }

}

//this should not be changed function checkQuestionRadio(radioGroup) {

//go through the radio group sent in and determine if radio button //checked is "correct". //return 1 for correct value, 0 for incorrect

  for (i=0; i<radioGroup.length; i++) {
    if (radioGroup[i].checked) {
      if (radioGroup[i].value == "correct") {
        return 1;
      }
      else {
        return 0;
      }
    }
  }

return 0; }

//this should not be changed function highlightCorrectButton(radioButton) {

  document.getElementById(radioButton).style.backgroundColor = highlightColor;

}

function checkQuiz() {

  //check each question to see if it's right.
  //The orange highlighted code may need to be changed
  //you will need to match these question types(Radio/DropDown)
  //and names (q1, q2, ...) to the ones in your quiz
  numCorrect = 0;
  numCorrect += checkQuestionRadio( document.quiz.q1);
  numCorrect += checkQuestionRadio( document.quiz.q2);
  numCorrect += checkQuestionRadio( document.quiz.q3);
  numCorrect += checkQuestionDropDown( document.quiz.q4);
 //highlight correct answers from radio button groups...use span id name
  highlightCorrectButton('correct1');
  highlightCorrectButton('correct2');
  highlightCorrectButton('correct3');
  //produce output in textarea.
  document.quiz.output.value +=
    "You got " + numCorrect + " out of 4 questions correct.\n" +
    "Your grade is " + Math.round(100*numCorrect/4) + "%\n" +
   "The answer to question 1 is HyperText Markup Language\n" +
   "The answer to question 2 is Jefferson City\n" +
   "The answer to question 3 is talking\n" +
   "The answer to question 4 is mass\n";

}