View Full Version : making javascript quizzes


nesianmysticfan
04-09-2004, 09:54 AM
Heres a totorial that I made which is how to make a javascript quiz.

Making the quiz
Ok, first you need to put this code onto your page anywhere:
<script><!-- hide
var ans = new Array;
var done = new Array;
var score = 0;

ans[1] = "a";
ans[2] = "a";
ans[3] = "a";
ans[4] = "a";
ans[5] = "a";
ans[6] = "a";
ans[7] = "a";
ans[8] = "a";
ans[9] = "a";
ans[10] = "a";

function Engine(question, answer) {
if (answer != ans[question]) {
if (!done[question]) {
done[question] = -1;
alert("Wrong!\n\nYour score is now: " + score);
}
else {
alert("You already answered that question");
}
}
else {
if (!done[question]) {
done[question] = -1;
score++;
alert("Right! \n\nYour score is now: " + score);
}
else {
alert("You already answered that question");
}
}
}

function NextLevel () {
if (score >= 7 && score <= 11) {
alert("Note if got 7 or more right ")
self.location="Address after ok click"
}
else {
alert("Note if scored less then 7")
}
}

//-->
</script>
you can edit the parts in bold and some of the other things too. now make the form by going:
<input type="radio" value="a" onclick="Engine(1, this.value)">
the engine part you have to edit to make it the right question. 1 means question 1. the value tells the code what answer it is (a,b,c) to tell if it was right or wrong. then when you have finished the questions, make a submit button by going:
<input type="button" value="The text you want the button to say" onclick="NextLevel()">
then save the page as a html page and it should work.
If you need anymore help, Private Message me.

DuncansOneLove
04-24-2004, 06:10 PM
How do i add text to go at the side of the little circle so they know which one to choose?

DuncansOneLove
04-24-2004, 06:26 PM
How do i add text to go at the side of the little circle so they know which one to choose?


You can forget that question now.

The problem i am having is with the actual quiz. How do i make it so there;s a question with 4 possible answers but only one is correct and yet the other wrong answers don't become the correct ones?

kbookworm
04-28-2004, 12:55 AM
neato! I don't quite understand though... is that one of the right or wrong ones, or is one of the 'what are you' ones?