﻿/************************************************************************************\
*                                                                                   *
*  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 = 'T'
       var cor3 = 'WIMAX FORUM'
       var cor5 = 'HO'
       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]==true) && (ans2[1]==true) && (ans2[2]==false) && (ans2[3]== false) ) {
       	   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 */
       
	   var ans3 = document.wq.Q3.value.toUpperCase()

       /* 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 */
	   var ans4 = new Array()
	   for (i=0;i<document.wq.Q4.length;i++) {
	   	   		ans4[i] = eval("document.wq.Q4[i].checked")
	   }
 
       /* Q4 correct or wrong */
       if ( (ans4[0]==true) && (ans4[1]==true) && (ans4[2]==false) && (ans4[3]==false) ) {
          sig[3] = imgtrue
		  x++
	   }
	   /* Q4 validation */
	   else if ( (ans4[0]==false) && (ans4[1]==false) && (ans4[2]==false) && (ans4[3]==false) ) {
          alert ("You haven't answered Question 4")
          return
       }
       /* put the correct or wrong sign */
       else 
          sig[3] = imgwrong
      
      
     /* Question 5 */
           
     for (i=0; i<document.wq.Q5.length; i++) {
	 if (document.wq.Q5[i].checked)
	    var ans5 = document.wq.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)
         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."
         
}


