// JavaScript Document

<!-- Quiz Code Module for M. D. Anderson Cancer Center
// Created December 2004 by J. W. Breeden/LiveAir Networks

var ans = new Array;
var done = new Array;
var kidAns = new Array;
var numQs = 0;
var tftranslatecancel=0;
//var explainAns = new Array;

var score = 0;
var percent = 0;
var scored = 0;
//define answers to each question in the page itself. 
//use format ans[#]="t";
//example ans[1]="t";
//number of questions goes in variable numQs.

function handler(question, answer) {
kidAns[question] = answer;
}

function tfexpand(gi) {
if (tftranslatecancel==0) {
switch (gi) {
case 't':
  return 'True';
  break
case 'T':
  return 'True';
  break
case 'f':
  return 'False';
  break
case 'F':
  return 'False';
  break
default:
  t1 = gi.toUpperCase();
  return t1;
}
}
 t1 = gi.toUpperCase();
 return t1
}

function Score(){
var score = 0;

var percent = 0;
var answerText = "How did you do?\n---------------------------\n";
for(i=1;i<=numQs;i++){
answerText = answerText + "\nQuestion "+i+"\n";
if(ans[i]!=kidAns[i]){
answerText = answerText + "\nIncorrect! The correct answer was " + tfexpand(ans[i]) + "\n";
}
else {
answerText = answerText + "\nCorrect! \n";
score++;
}
}

//calculate a percentage
percent = score / numQs;
percent = 100 * percent;
percent = Math.round(percent);

answerText = answerText + "\n\n Your total score is: "+score+" out of "+numQs+", or "+percent+"%.\n";

if(percent < 70) {
answerText = answerText + "You Failed.";
next=0;
}
if (percent >= 70 && percent < 80) {
answerText = answerText + "You passed with a 'C'.";
next=0;
}
if (percent >=80 && percent < 90)  {
answerText = answerText + "You passed with a 'B'.";
next=0;
}
if (percent >=90 && percent < 100)  {
answerText = answerText + "You passed with an 'A'.";
next=0;
}
if (percent == 100)  {
answerText = answerText + "You passed with a perfect score! Congratulations!";
next=1;
}
if (percent > 100)  {
answerText = answerText + "You are better than perfect! You should be a scientist!";
next=1;
}
scored=1
alert(answerText);

}


function nextChk(url){
if (scored==0) {
alert("You must take the quiz before continuing.");
}
if (scored==1) {
if (next==1) {
alert("Thank you for completing this chapter with a perfect score.");
document.location.href=url;
} 
if (next==0) {
alert("You must have a perfect score to continue.");
}
}
}
-->