Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: fast quiz

  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Posts
    433
    Thanks
    3
    Thanked 0 Times in 0 Posts

    fast quiz

    Hi.... i need to implement a fast quiz in Javascript... I don't care if the results will be in the source code because the quiz is only for small kids..... I want the children to check some options and then the error and correct answers appear in the correct color...
    Thx

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Are these yes no questions? Need a bit more info. . . Have you attempted this at all or are you just looking for someone to write it for you. If you've attempted it, post what you have.

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Posts
    433
    Thanks
    3
    Thanked 0 Times in 0 Posts

    nop

    Yes it is yes or no game quiz.. No i haven't tried not because i am bored but because i have really no time... I have too much work for tomorrow....
    If u can help me i will appreciate it really

  • #4
    JPM
    JPM is offline
    Regular Coder
    Join Date
    Mar 2004
    Location
    Norway
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Searched google and this was the first thing to pop up.
    script
    <JPM />

  • #5
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    And here is a quick one I whipped up.

    Code:
    <html>
    <head>
    <style type="text/css">
    
    table
    {
    	text-align:center;
    }
    
    th
    {
    	background-color:#333399;
    	color:#FFF;
    }
    
    td
    {
    	border:solid 1px;
    }
    </style>
    <script type="text/javascript">
    
    //Modify your questions and answers here.  Add as many as you like.
    var QA=new Array()
    QA[0]=new Array("Question0","Y");  
    QA[1]=new Array("Question1","N");
    QA[2]=new Array("Question2","Y");
    QA[3]=new Array("Question3","N");
    QA[4]=new Array("Question4","Y");
    QA[5]=new Array("Question5","N");
    QA[6]=new Array("Question6","N");
    QA[7]=new Array("Question7","Y");
    QA[8]=new Array("Question8","N");
    QA[9]=new Array("Question9","Y");
    
    function fillQuiz()
    {
    	str='<table>'+
    			'<thead>'+
    				'<th>#</th>'+
    				'<th>Question</th>'+
    				'<th>Yes</th>'+
    				'<th>No</th>'+
    			'</thead>';
    				
    	for(i=0;i<QA.length;i++)
    	{
    		var j=i+1;
    		var pass1='Y'+i;
    		var pass2='N'+i;
    		str+='<tr>'+
    				'<td>'+j+'</td>'+
    				'<td>'+QA[i][0]+'</td>'+
    				'<td><input onclick=checkHandler('+pass2+',this.checked) type="checkbox" id="Y'+i+'" /></td>'+
    				'<td><input onclick=checkHandler('+pass1+',this.checked) type="checkbox" id="N'+i+'" /></td>'+
    			'</tr>';
    	}
    	str+='<tr><td colspan="4"><input type="button" onclick="correctQuiz()" value="Check Answers"></table>';
    	document.getElementById('test').innerHTML=str;
    }
    
    function checkHandler(box1,box2)
    {
    	if(box2)
    	{
    		box1.checked=false;
    	}
    }
    
    function correctQuiz()
    {
    	for(i=0;i<QA.length;i++)
    	{
    		var j=i+1;
    		var A1='Y'+i;
    		var A2='N'+i;
    		A1ck=document.getElementById(A1).checked;
    		A2ck=document.getElementById(A2).checked;
    		var ans="";
    		if(A1ck)
    		{
    			ans="Y";
    		}
    		else if(A2ck)
    		{
    			ans="N";
    		}
    		else
    		{
    			alert("You didn't answer question number "+ j);return
    		}
    		if(ans==QA[i][1])
    		{
    			document.getElementById(A1).style.backgroundColor='green';
    		}
    		else
    		{
    			document.getElementById(A1).style.backgroundColor='red';
    		}
    	}
    }
    		
    </script>
    </head>
    <body onload="fillQuiz()">
    <div id="test">
    </div>
    </body>
    </html>
    Basscyst
    Last edited by Basscyst; 07-18-2004 at 06:17 PM.
    Helping to build a bigger box. - Adam Matthews


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •