473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Creating multiple choice quiz

Hello Everyone,

I am a beginner in Javascript.I want to create fun quiz tool using
javascript (no database). The feature of that tool is every question
has five choices. The user needs to select three best choices. If they
do, a message window pops up which says good choices or something and
take them to next question. If they don't choose all of the best
choices they get another message like try again but these are not the
best choices and take them back to the same question. Is there any
tutorial which could help me do this or has anyone done something like
this before, which could help me.

VR
Jul 23 '05 #1
5 5722
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*?

I am just *kidding*, sheeshhh!! ;-)

...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..

*Unless*.. the Javascript is server-side (very rare)
or you have help from a server side database, or
other server side 'adjudicator' that simply takes
the answers and tells the student 'right/wrong'.

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #2
Lee
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'>&nbsp;"+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>

Jul 23 '05 #3
Lee <RE**************@cox.net> wrote in message news:<cd********@drn.newsguy.com>...
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'>&nbsp;"+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>


Thank you both for replying my question. Lee, I tried to execute the
code you wrote here. I am getting an error "object expected" in line
where we have <body onload="nextQuestion()">. I checked the code but
couldn't find any error. Could you help me.
Jul 23 '05 #4
Lee
Vandana Rola said:

Thank you both for replying my question. Lee, I tried to execute the
code you wrote here. I am getting an error "object expected" in line
where we have <body onload="nextQuestion()">. I checked the code but
couldn't find any error. Could you help me.


Sorry, I hadn't tested in IE.
Remove the comma from the end of this line:

key: "7026339154",

Mozilla let that mistake slide.

Jul 23 '05 #5
Lee <RE**************@cox.net> wrote in message news:<cd*********@drn.newsguy.com>...
Vandana Rola said:

Thank you both for replying my question. Lee, I tried to execute the
code you wrote here. I am getting an error "object expected" in line
where we have <body onload="nextQuestion()">. I checked the code but
couldn't find any error. Could you help me.


Sorry, I hadn't tested in IE.
Remove the comma from the end of this line:

key: "7026339154",

Mozilla let that mistake slide.

I am using the code provided by Lee above to create this tool.
There is one more improvement I would like to make here:
I would like to give the feedback for all the checked answers. Like
in the questions below:
Which are odd numbers:
2
3
4
5
13

if the user selects 2, 3, 5, then I would like to give feedback as
below:
2 Incorrect, 2 is an even number
3 correct
5 correct

I tried to make the improvement in the following function to
accomplish this:

function check(f,key){
var newhtml="";
key=key.replace(/^.*0/,"").substr(0,5);
for(var i=0;i<key.length;i++) {
if ((key.charAt(i)<"5")==f.elements[i].checked)
{
newhtml+= question.a[i] + "<br>Right.<br>";
}
else if ((key.charAt(i)>"5")==f.elements[i].checked)
{
newhtml+= question.a[i] + " <br>Wrong.<br>";

}
else {return};
}
document.getElementById("tablet").innerHTML= newhtml;

It gives me correct feedback for the checked answers. But it also
checks the unchecked answers( which I would like to ignore) and gives
me reverse feedback. e.g. even if 4 and 13 are unchecked it gives
feedback 4 is an odd number and 13 is an even number. Is there a way
to tell JAVAscript to ignore something and do not write it too. I
tried empty statements, but they didn't work either. I really
appreciate your help.

Thanks
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mohammed Mazid | last post by:
Can anyone please give me some clues on how to track the right answers in multiple-choice type questions (using checkbox) and single-choice questions (rdio buttons) and also how to store the right...
9
by: cppaddict | last post by:
I have a method that uses a fairly large object. The choice is between having a local object in the method or a static member object that the method uses. ------CHOICE 1--------- int...
4
by: Dave Parrin-Bull | last post by:
Hi all, I have been asked (nay told!) to do a quiz for a webpage at work, now I can do the basic things like getting the radio boxes up there and assign values to them but here is what they...
10
by: connyledin | last post by:
Im trying to create a version of the game Wumpus. Mine is called Belzebub. But im STUCK! And its due tuesday 2 maj. Im panicing! Can some one help me?? here is the file:...
0
NoPeasHear
by: NoPeasHear | last post by:
I don't know what I am doing wrong... I used this tutorial... http://www.permadi.com/tutorial/flashMXQuiz/index.html It works with their quiz.xml file, but when I add an option for multiple...
1
by: kixter1108 | last post by:
Hi guys! I'm seeking help in creating a quiz that would allow the user to change the questions/answers as an option on the interface itself. Is it possible? What database interconnection would be...
6
nomad
by: nomad | last post by:
I have a general question on how to select multiple question on a quiz. The quiz is done in html and php, with a post method. The post info connect to a php file. By the way the the guess are A,...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
3
by: brian210 | last post by:
I am currently trying to make a four question quiz. Each question is on a new page. There will be a previous button and a next button to take the user to the previous and next question respectively....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.