var ans = new Array;
var done = new Array;
var yourAns = new Array;
var explainAnswer = new Array;



// Part 1 - Correct answers for each questions 

var score = 0;
ans[1] = "b";
ans[2] = "d";
ans[3] = "a";
ans[4] = "c";
ans[5] = "d";


// Part 2: Give a brief expanation for the correct answerfor questions 

explainAnswer[1]="Reflection occurs when light waves bounce off an object";
explainAnswer[2]="Refraction is the bending of light as it changes speed";
explainAnswer[3]="Translucent materials scatter light";
explainAnswer[4]="Opaque materials absorb light";
explainAnswer[5]="The Law of Reflection states that the angle of incidence is equal to the angle of reflection";



function Engine(question, answer) {
yourAns[question]=answer;
}

function Score(){
	var answerText = "";
	for(i=1;i<=5;i++){
   		answerText=answerText+"<br><b>Question :"+i+"</b><br>";
  		if(ans[i]!=yourAns[i]){
    		answerText=answerText+"The correct answer was <font size='+1'><i><u>" + ans[i] + "</u></i></font><br>" + explainAnswer[i] + "<br>";
  		}
  		else{
    		answerText=answerText+" Correct! <br>";
    		score++;
  		}
	}

	answerText=answerText+"<p><font size='+1'>Your total score is : "+score+"</font></p>";

	//now score the user

	// Part 3: Optional.  You may change the comments for each score from 0 to 5.

	answerText=answerText+"<b>Comment :</b> ";
	if(score<=0){
	answerText=answerText+"You must hate quizzes!";
	}
	
	if(score>=1 && score <=1){
	answerText=answerText+"Take the quiz again";
	}
	
	if(score>=2 && score <=2){
	answerText=answerText+"Guessing does not count";
	}
	
	if(score>=3 && score <=3){
	answerText=answerText+"You have signs of intelligence";
	}
	
	if(score>=4 && score <=4){
	answerText=answerText+"Very good";
	}
	
	
	if(score>=5 && score <=5){
	answerText=answerText+"You are a genius!";
	}
	
	makeNewWindow(answerText);
	//alert(answerText);

}

var newWindow
function makeNewWindow(myText){
	if(!newWindow || newWindow.closed){
	newWindow = window.open("","","scrollbars,height=480,width=360");
		if(!newWindow.opener){
			newWindow.opener = window;
		}
		// content of new window
		var newContent = "<html><head><title>Quiz Results</title></head>";
		newContent += "<body><h2 style='text-align: center'>How Did You Do?</h2>" + myText;
		newContent += "</body></html>";
		// write HTML to new window document
		newWindow.document.write(newContent);
		newWindow.document.close(); //close layout stream
		} else{
		//the window is already open - bring to front
		newWindow.focus();
	
	}
}
