Confirm Test With Results Computed

[Total: 0    Average: 0/5]

This shows how to have a test run using confirm alerts to have the user enter in TRUE or FALSE for each question.

Body Code:

<script type=text/javascript>
var Qs = new Array(); //questions
var As = new Array(); //answers
var Rs = new Array(); //results
var instructions = "n[OK=yes & CANCEL=no]";
function addQnA(_q,_a) {
  var spot = Qs.length?Qs.length:0;
  Qs[spot] = _q;
  As[spot] = _a;
}
addQnA("Is 5+5 10?",true);
addQnA("Is 5+5 9?",false);
addQnA("Is 2+2 4?",true);
addQnA("Is 2+2 3?",false);
function askQs() {
  for (var i in Qs) {
    Rs[i] = confirm(Qs[i]+instructions);
  }
  showResults();
}
function showResults() {
  var numRight = 0;
  for (var i in As) {
    numRight += As[i]==Rs[i]?1:0;
  }
  alert("You got "+numRight+" correct!");
}
</script>
<BR><a href="javascript:askQs()">Start Test</a>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *