<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Self Assessment with Answers Given</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--

var numQues = 3;
var numChoi = 3;

var answers = new Array(3);
answers[0] = "50";
answers[1] = "13";
answers[2] = "3";

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;

}

// -->
</script>
</head>

<body>

<form name="quiz">
1. How many stars are on the American Flag?<br>
<input type="radio" name="q1" value="1">1<br>
<input type="radio" name="q1" value="51">51<br>
<input type="radio" name="q1" value="50">50<br>
<p>

2. How many stripes are on the American Flag?<br>
<input type="radio" name="q2" value="1">1<br>
<input type="radio" name="q2" value="13">13<br>
<input type="radio" name="q2" value="50">50<br>
<p>

3. How many colors are on the American Flag?<br>
<input type="radio" name="q3" value="3">3<br>
<input type="radio" name="q3" value="2">2<br>
<input type="radio" name="q3" value="1">1<br>
<p>

<input type="button" value="Get score" onClick="getScore(this.form)">
<input type="reset" value="Clear"><p>
Score = <input type=text size=15 name="percentage"><br>
Correct answers:<br>
<textarea name="solutions" wrap="virtual" rows="4" cols="40"></textarea>
</form>

<body>

</body>
</html>
