﻿/************************************************************************************\
*                                                                                   *
*  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 checkitwq() {
       var i
       var x = 0
       var cor1 = 'MIMO'
       var cor3 = 'WiFi-abg'
       var cor4 = 'STC'
       var imgtrue = 'images/true.gif'
       var imgwrong = 'images/wrong.gif'
       var sig = new Array()
                   
      /* ============================== Question 1 ==================================================== */            
       for( i=0; i<document.wq.Q1.length; i++) {
	      if (document.wq.Q1[i].checked)
	          var ans1 = document.wq.Q1[i].value
	   }
	   
	   /* Q1 validation */
	   if (ans1 == null) {
	       alert ("You haven't answered Question 1")
	       return
	   }
	   /* Q1 correct or wrong */
	   if (ans1 == cor1) {
	   	  sig[0] = imgtrue
	   	  x++
	   }
	   /* put the correct or wrong sign */
	   else
	      sig[0] = imgwrong
	  
      /* ================================ Question 2 =================================================== */ 
	   
	   var ans2 = new Array()
	   
	   for (i=0;i<document.wq.Q2.length;i++) {
	   	   		ans2[i] = eval("document.wq.Q2[i].checked")
	   }
	   
	   /* Q2 correct or wrong */
	   if ( (ans2[0]==false) && (ans2[1]==true) && (ans2[2]==true) && (ans2[3]==true) ) {
       	   sig[1] = imgtrue
       	   x++
       } 
       /* Q2 validation */
       else if ( (ans2[0]==false) && (ans2[1]==false) && (ans2[2]==false) && (ans2[3]==false) ) {
           alert ("You haven't answered Question 2")
           return
       }
       /* put the correct or wrong sign */
       else 
	      sig[1] = imgwrong

      /* =================================  Question 3 =================================================== */
       
	   for(i=0; i<document.wq.Q3.length; i++) {
	      if (document.wq.Q3[i].checked)
	          var ans3 = document.wq.Q3[i].value
	   }
	   
	   /* Q3 validation */
	   if (ans3==null) {
	       alert ("You haven't answered Question 3")
	       return
	   }
	   /* Q3 correct or wrong */
	   if (ans3==cor3) {
	   	  sig[2] = imgtrue
	   	  x++
	   }
	   /* put the correct or wrong sign */
	   else
	      sig[2] = imgwrong
    
     /* ============================== Question 4 ==================================================== */            
       for(i=0; i<document.wq.Q4.length; i++) {
	      if (document.wq.Q4[i].checked)
	          var ans4 = document.wq.Q4[i].value
	   }
	   
	   /* Q4 validation */
	   if (ans4==null) {
	       alert ("You haven't answered Question 4")
	       return
	   }
	   /* Q4 correct or wrong */
	   if (ans4==cor4) {
	   	  sig[3] = imgtrue
	   	  x++
	   }
	   /* put the correct or wrong sign */
	   else
	      sig[3] = imgwrong
 
     /* ============================== Question 5 ==================================================== */            
       var ans5 = new Array()
	   
	   for (i=0;i<document.wq.Q5.length;i++) {
	   	   		ans5[i] = eval("document.wq.Q5[i].checked")
	   }
	   
	   /* Q5 correct or wrong */
	   if ( (ans5[0]==false) && (ans5[1]==true) && (ans5[2]==false) && (ans5[3]==true) ) {
       	   sig[4] = imgtrue
       	   x++
       } 
       /* Q5 validation */
       else if ( (ans5[0]==false) && (ans5[1]==false) && (ans5[2]==false) && (ans5[3]==false) ) {
           alert ("You haven't answered Question 5")
           return
       }
       /* put the correct or wrong sign */
       else 
	      sig[4] = imgwrong
	      
     /* ================================================================================================ */
     
	 /* 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)
         wqdiv.innerHTML = "Congratulations! Excellent score."
     else if (score==80)
         wqdiv.innerHTML = "Very Good!, you scored "+x+" out of 5."
     else if (score==60)
         wqdiv.innerHTML = "Good!, you scored "+x+" out of 5."
     else
         wqdiv.innerHTML = "Sorry, you need to learn more."
         
}


