Andrew Thompson said:
On 20 Jul 2004 14:01:00 -0700, Vandana Rola wrote:
or has anyone done something like
this before, which could help me.
A quiz type thing? No.. I don't think so,
..is such a thing even *possible*?
..hmmm lemme see.. start with these 3900 or so..
<http://www.google.com/search?q=%22javascript+source%22+quiz>
But then, you realize that any test written in
(client side) Javascript can be 'cracked' by the
students if they can read Javascript? They can
read the Javascript itself for the answers..
Not many of those 3900 examples will fill the OP's requirement
of having three correct answers for each question.
Here's a simple example that also shows that you can make it
non-trivial to read the answers from the client-side script.
In this case, it's not really very hard, but still may be
more trouble than it's worth.
The correct answers are encoded in the "key" attribute as:
Ignore everything except the 5 digits that immediately
follow the first zero.
Those 5 digits correspond to the 5 answer choices.
If the digit is less than 5, then that choice is one
of the correct answers.
<html>
<head>
<script type="text/javascript">
quiz = [ {q: "Which are odd numbers?",
a: ["7", "3", "15", "12", "0"],
key: "631013287575"
},
{q: "Which are U.S. States?",
a: ["Utah", "Apache", "Maine", "Sonora", "Florida"],
key: "2401738283"
},
{q: "Which are mammals?",
a: ["skunk", "tarantula", "dolfin", "human", "aligator"],
key: "7026339154",
}
];
function nextQuestion(){
var question=quiz.pop();
var html="<p>"+question.q+"</p><form>";
for(var i=0;i<question.a.length;i++){
html+="<input type='checkbox'> "+question.a[i]+"<br>";
}
html+="<input type='button' value='Done' onclick='check(this.form,\""
+question.key+"\")'></form>";
document.getElementById("tablet").innerHTML=html;
}
function check(f,key){
key=key.replace(/^.*0/,"").substr(0,5);
for(var i=0;i<key.length;i++) {
if ((key.charAt(i)<"5")!=f.elements[i].checked) {
document.getElementById("tablet").innerHTML+=
"<p>Wrong! Try again.</p>";
return;
}
}
document.getElementById("tablet").innerHTML+="<p>R ight!</p>";
if(quiz.length){
setTimeout("nextQuestion()",500);
} else {
document.getElementById("tablet").innerHTML="<p>Do ne!</p>";
}
}
</script>
</head>
<body onload="nextQuestion()">
<div id="tablet"></div>
</body>
</html>