...

View Full Version : fast quiz



alaios
07-18-2004, 04:02 AM
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

Basscyst
07-18-2004, 05:52 PM
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

alaios
07-18-2004, 06:08 PM
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

JPM
07-18-2004, 06:37 PM
Searched google and this was the first thing to pop up.
script (http://wsabstract.com/script/script2/comboquiz.shtml)

Basscyst
07-18-2004, 07:08 PM
And here is a quick one I whipped up.



<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum