﻿/************************************************************************************\
*                                                                                   *
*  You've come to this place because you are a savvy Web user or a curious person.  *
*  Fyi, this script was developed inhouse specially for www.conniq.com              *
*  quiz solution. Although using very basic JavaSript programming knowledge,        *
*  I incorporate some cool features, like adding correct or wrong sign,             *
*  inner html insert, and multiple types of questions.                              *
*                                                                                   *
\************************************************************************************/

var score
var tries = 0
function checkitgq() {
       var i
       var x = 0
       var cor2 = '2.5G'
       var cor3 = 14.4
       var cor4 = 'GPRS'
       var cor5 = 'packet'
       var imgtrue = 'images/true.gif'
       var imgwrong = 'images/wrong.gif'
       var sig = new Array()
       
       /* Question 1 */ 
	   
	   var ans1 = new Array()
	   
	   for (i=0;i<document.gq.Q1.length;i++) {
	   	   		ans1[i] = eval("document.gq.Q1[i].checked")
	   }
	   
	   /* Q1 correct or wrong */
	   if ( (ans1[0]==false) && (ans1[1]==true) && (ans1[2]==true) && (ans1[3]== false) ) {
       	   sig[0] = imgtrue
       	   x++
       } 
       /* Q1 validation */
       else if ( (ans1[0]==false) && (ans1[1]==false) && (ans1[2]==false) && (ans1[3]==false) ) {
           alert ("You haven't answered Question 1")
           return
       }
       /* put the correct or wrong sign */
       else 
	      sig[0] = imgwrong
       
       /* Question 2 */            
       for(i=0; i<document.gq.Q2.length; i++) {
	   
	   if (document.gq.Q2[i].checked)
	      var ans2 = document.gq.Q2[i].value
	   }
	   /* Q2 validation */
	   if (ans2 == null) {
	       alert ("You haven't answered Question 2")
	       return
	   }
	   /* Q2 correct or wrong */
	   if (ans2 == cor2) {
	   	  sig[1] = imgtrue
	   	  x++
	   }
	   /* put the correct or wrong sign */
	   else
	      sig[1] = imgwrong
	   
	      
       /* Question 3 */
       
	   var ans3 = document.gq.Q3.value
	   
	   /* Q3 correct or wrong */
       if (ans3 == cor3) {
           sig[2] = imgtrue
           x++
       }
       /* put the correct or wrong sign */
       else
	       sig[2] = imgwrong
       
       /* Q3 validation */       
       if (ans3 == "") {
	       alert ("You haven't answered Question 3")
	       return
	   }
	   
	 /* Question 4 */
           
     for (i=0; i<document.gq.Q4.length; i++) {
	 if (document.gq.Q4[i].checked)
	    var ans4 = document.gq.Q4[i].value
	 }
	 
     /* Q4 correct or wrong */  
	 if (ans4 == cor4) {
	      sig[3] = imgtrue
	      x++
	 }
	 else
	      sig[3] = imgwrong
	 
     /* Q4 validation */ 
     if (ans4 == null) {
	     alert ("You haven't answered Question 4")
	     return
     }

	   	         
     /* Question 5 */
           
     for (i=0; i<document.gq.Q5.length; i++) {
	 if (document.gq.Q5[i].checked)
	    var ans5 = document.gq.Q5[i].value
	 }
	 
     /* Q5 correct or wrong */  
	 if (ans5 == cor5) {
	      sig[4] = imgtrue
	      x++
	 }
	 else
	      sig[4] = imgwrong
	 
     /* Q5 validation */ 
     if (ans5 == null) {
	     alert ("You haven't answered Question 5")
	     return
     }
 
	 /* put the correct or wrong sign */
	 
	 for (i=0;i<5;i++) {
	     eval("document.myImage"+i).src = sig[i]
	 }
	 
     score = (x/5)*100
     tries++   
     
     alert("You answered "+x+" correctly."+" Your score is "+score+"%. "+"You've tried "+tries+" times.")
     
     if (score==100)
         gqdiv.innerHTML = "Congratulations! Excellent score."
     else if (score==80)
         gqdiv.innerHTML = "Very Good!, you scored "+x+" out of 5."
     else if (score==60)
         gqdiv.innerHTML = "Good!, you scored "+x+" out of 5."
     else
         gqdiv.innerHTML = "Sorry, you need to learn more."
         
}


