PDA

View Full Version : Perfecting Results of a Quiz


jv00123
12-15-2002, 04:42 PM
ok, i have a fill in the blank quiz and it shows the results in a new page when you click to check them.

.1. i wanted to know if there is a way to have it automaticaly save the results to maybe a log file or maybe email them.

.2. as of now, the results will say " you answered ..... for question 1. <br> you answered ..... for question 2" etc... what i would like it do is to say if they got that certain question correct or incorrect.

.3. finally, if its possible to make the log file, how would you make the results page display the average scores of everyone who took it. or average correct or incorrect on a certain question?

If anyone could answer any one of my questions, please do. Thanks and i'll paste the results page code in here, and attach the rough quiz code since its long because of its repetitiveness.


<script type="text/javascript">
function tst() {
cook = unescape(document.cookie)
vals = cook.split(";")
document.write("You answered <b>" + vals[0] + "</b> for number 1.<br>You answered <b>" + vals[1] + "</b> for number 2.<br>You answered <b>" + vals[2] + "</b> for number 3.<br>You answered <b>" + vals[3] + "</b> for number 4.<br>You answered <b>" + vals[4] + "</b> for number 5.<br>You answered <b>" + vals[5] + "</b> for number 6.<br>You answered <b>" + vals[6] + "</b> for number 7.<br>You answered <b>" + vals[7] + "</b> for number 8.<br>You answered <b>" + vals[8] + "</b> for number 9.<br>You answered <b>" + vals[9] + "</b> for number 10.<br>You got <b>" + vals[10] + "</b> correct and <b>" + vals[11] + "</b> incorrect.<br>You got <b>" + vals[10]/10 * 100 + "</b>% correct.");
}
</script>
</head>
<body onLoad="tst()">
<span id="spanname"></span>
</body>

joeframbach
12-15-2002, 10:39 PM
lol... everyone is making quizzes for some reaseon. this is the third time ive posted this one that i made....

jv00123
12-15-2002, 11:46 PM
thats just a multiple choice quiz that shows percent right, and how many right...........the one i have shown does the same. If you make mine into an html, you will see its much different than that.

joeframbach
12-16-2002, 12:09 AM
yes, i see. my script can be easily changed. i made it with an array so a question can be added without having to change a bunch of code. just so its easier to unbug and etc.

joeframbach
12-16-2002, 12:25 AM
i changed it around a bit. have fun

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
var questions=[
["what is my favorite color?","black"],
["what gender am i?","guy"],
["what is my favorite programming language?","javascript"],
["what grade am i in?","11"]
];
var list="<FORM name=test>";
for(var i=0;i<questions.length;i++)
{
list+="<A name=question"+i+">Question "+(i+1)+"</A>: "+questions[i][0]+"<BR>";
list+="<INPUT type=text name=answer"+i+"><BR>";
}
list+="<INPUT type=button value=\"submit\" onClick=\"grade()\"></FORM><A id=score></A>";
document.write(list);
function grade()
{
var score=0;
for(var i=0;i<questions.length;i++)
if(eval("document.test.answer"+i).value.toUpperCase()==questions[i][1].toUpperCase())
score++;
else eval("document.getElementById('question"+i+"')").style.color='red';
document.getElementById("score").innerHTML=score+" / "+questions.length+" = "+(score*100)/(questions.length)+"%";
}
-->
</SCRIPT>
</HEAD>
</HTML>

chrismiceli
12-16-2002, 12:58 AM
i do admit my code i wrote is pretty static, i didn't really have time to make it dynamic at all.:(

jv00123
12-16-2002, 01:32 PM
How would i make more than one answer correct with that script?

joeframbach
12-16-2002, 01:57 PM
just add more answers to the array
var questions=[[q1,a1,a2],[q2,a1,a2],[q3,a1,a2]];

also change the grade function to this:
function grade()
{
var score=0;
var c=false;
for(var i=0;i<questions.length;i++)
{
c=false;
for(var j=1;j<questions[i].length;j++)
if(eval("document.test.answer"+i).value.toUpperCase()==questions[i][j].toUpperCase())
c=true;
if(c==false)
eval("document.getElementById('question"+i+"')").style.color='red';
else score++;
}
document.getElementById("score").innerHTML=score+" / "+questions.length+" = "+(score*100)/(questions.length)+"%";
}

jv00123
12-16-2002, 11:25 PM
how would i go about showing the percentage of people who have gotten each one right or wrong? would i have to make the quiz save the results of whoever takes it to a log or something?

jv00123
12-16-2002, 11:49 PM
also, the script you gave me wont allow me to add more than 5 questions....why is there a limit?

Palanturiel
07-18-2003, 12:24 AM
hey people. I'm new here, but I found a good quiz script at this link: http://javascriptkit.com/script/cut180.shtml it gives unlimited questions, and is very easy to change (if i can, im sure you can). :thumbsup: but i have one question regarding that script. I was wondring if anyone knows if i can have it email me their results and show them their results. I'd post the part of the script, but im not sure which part to use. Really sorry. I wish i could be more specific, but I'm a rookie. (don't b mad at me :D )
Alrighty, thanx, and i hope that link helped.

Geez, I just realized how old this thread is. O well, i'll try to help anyway :o

Vladdy
07-18-2003, 01:38 AM
this thread may be of interest:
http://www.codingforums.com/showthread.php?s=&threadid=22295

Palanturiel
07-18-2003, 07:05 AM
Thanx, but if at all possible, I'd like to use the quiz that i have. I was hoping that i could just add an email link for when they hit the "Grade Quiz" button, or something of that sort. Here is the script from the quiz that I think would be needed to do that. If its the wrong part or you need script from the results page to do it, just tell me. Like I said, im not really sure what I need to do. Oh, and I'm not asking for anyone to do it for me, I just need instructions.

here's the quiz script that I think you'd need:
<form>
<div align="center">
<input type="button" value="Grade Me!" name="B1" onClick="gradeit()"> <input type="button" value="Reset" name="B2" onClick="document.myquiz.reset()"></div>
</form>
It's the script for the Submit button and the reset button. hope this is useful to someone. :D

Vladdy
07-18-2003, 01:15 PM
E-mail function can only be implemented (I dismiss the mailto: as combersome and unreliable) on the server side.
In general, javascript quizes are better suited for educational and entertainment purposes. If you want a test where results are important, look for server side solution.

Palanturiel
07-18-2003, 07:34 PM
Umm... I'm not sure what that means. Could you explain it a little more, please?

arnyinc
07-18-2003, 08:04 PM
Originally posted by Palanturiel
Umm... I'm not sure what that means. Could you explain it a little more, please?

JavaScript doesn't have all the capabilities that you seek. JavaScript is a client side language, so you can't create a log on the server and you can't submit the quiz via email consistently. You have to rely on every user having their email client set up and being willing to send you their email address.

Palanturiel
07-18-2003, 08:28 PM
hmm.. ok. well, then would i possibly be able to create a button on the results page that they could click if they wanted to email me their results?
Here is the script for the other buttons on the results page. I'm hoping that there is a way to make another one? if u need to see something else, then just tell me.

<input type="button" value="Take the quiz again" name="B1"
onClick="history.go(-1)"> <input type="button" value="View solution" name="B2"
onClick="showsolution()"><p>

Really hoping that this can be made to work! :thumbsup: