PDA

View Full Version : Quiz

101
10-12-2002, 09:08 AM
I am making a quiz for a web site and i need just i litle help.

The only problem is that if you miss one of the questions out you get errors and stuff. So i though if i use true and false that should work but i think i did some thing wrong.

var Rtn = true; //i was going to add this to the top

if (value =="") //this under each question but it did not work
Rtn = false;

return Rtn; //this at the bottom
}

Can any one help me and one finaly thing can you make it so if you get a score from say 0 to 20 it says "you got ...% That was poor" and from 20-40 it says "you got ...% that was ok" and so on.

Can anyone help me on that?

Here is the basic script:

<HTML>
<TITLE>
</TITLE>
<BODY>

<Script Language="JavaScript">

function process() {

var f = document.f;
var i = 0;
var s = 0;
var t = 0;

for (i = 0; i < f.one.length; i++) if (f.one[i].checked) value = f.one[i].value;
if (value == "1") { s += 1; }
if (value == "5") { s += 5; }
if (value == "9") { s += 9; }
if (value == "10") { s += 10; }
for (i = 0; i < f.two.length; i++) if (f.two[i].checked) value = f.two[i].value;
if (value == "1") { s += 1; }
if (value == "2") { s += 2; }
if (value == "3") { s += 3; }
if (value == "10") { s += 10; }
for (i = 0; i < f.three.length; i++) if (f.three[i].checked) value = f.three[i].value;
if (value == "1") { s += 1; }
if (value == "3") { s += 3; }
if (value == "5") { s += 5; }
if (value == "10") { s += 10; }
for (i = 0; i < f.four.length; i++) if (f.four[i].checked) value = f.four[i].value;
if (value == "1") { s += 1; }
if (value == "2") { s += 2; }
if (value == "5") { s += 5; }
if (value == "10") { s += 10; }
for (i = 0; i < f.five.length; i++) if (f.five[i].checked) value = f.five[i].value;
if (value == "1") { s += 1; }
if (value == "3") { s += 3; }
if (value == "7") { s += 7; }
if (value == "10") { s += 10; }
for (i = 0; i < f.six.length; i++) if (f.six[i].checked) value = f.six[i].value;
if (value == "2") { s += 2; }
if (value == "5") { s += 5; }
if (value == "6") { s += 6; }
if (value == "10") { s += 10; }
for (i = 0; i < f.seven.length; i++) if (f.seven[i].checked) value = f.seven[i].value;
if (value == "1") { s += 1; }
if (value == "4") { s += 4; }
if (value == "6") { s += 6; }
if (value == "10") { s += 10; }
for (i = 0; i < f.eight.length; i++) if (f.eight[i].checked) value = f.eight[i].value;
if (value == "3") { s += 3; }
if (value == "6") { s += 6; }
if (value == "7") { s += 7; }
if (value == "10") { s += 10; }
for (i = 0; i < f.nine.length; i++) if (f.nine[i].checked) value = f.nine[i].value;
if (value == "1") { s += 1; }
if (value == "3") { s += 3; }
if (value == "7") { s += 7; }
if (value == "10") { s += 10; }
for (i = 0; i < f.ten.length; i++) if (f.ten[i].checked) value = f.ten[i].value;
if (value == "1") { s += 1; }
if (value == "3") { s += 3; }
if (value == "7") { s += 7; }
if (value == "10") { s += 10; }
alert("You Have Scored " + s + "%")

</Script>

<form name="f">
<B>1. Question1</B>
<BR>
<BR>
<BR>
<B>2. Question2</B>
<BR>
<BR>
<BR>
<B>3. Question3</B>
<BR>
<BR>
<BR>
<B>4. Question4</B>
<BR>
<BR>
<BR>
<B>5. Question5</B>
<BR>
<BR>
<BR>
<B>6. Question6</B>
<BR>
<BR>
<BR>
<B>7. Question7</B>
<BR>
<BR>
<BR>
<B>8. Question8</B>
<BR>
<BR>
<BR>
<B>9. Question9</B>
<BR>
<BR>
<BR>
<B>10. Question10</B>
<BR>
<BR>
<BR>

<input type="button" value="Score" onClick="return process();">

</form>

</BODY>
</HTML>

10-12-2002, 05:45 PM
This should do it

<HTML>
<TITLE>
</TITLE>
<BODY>

<Script Language="JavaScript">

function process() {

var f = document.f;
var i = 0;
var s = 0;
var t;
for(i=0;i<f.one.length;i++)
{
if(f.one[i].checked)
{
s=s+eval(f.one[i].value);
}
}

//all the rest looks the same as the above unfolded
for(i=0;i<f.two.length;i++){if(f.two[i].checked){s=s+eval(f.two[i].value);}}
for(i=0;i<f.three.length;i++){if(f.three[i].checked){s=s+eval(f.three[i].value);}}
for(i=0;i<f.four.length;i++){if(f.four[i].checked){s=s+eval(f.four[i].value);}}
for(i=0;i<f.five.length;i++){if(f.five[i].checked){s=s+eval(f.five[i].value);}}
for(i=0;i<f.six.length;i++){if(f.six[i].checked){s=s+eval(f.six[i].value);}}
for(i=0;i<f.seven.length;i++){if(f.seven[i].checked){s=s+eval(f.seven[i].value);}}
for(i=0;i<f.eight.length;i++){if(f.eight[i].checked){s=s+eval(f.eight[i].value);}}
for(i=0;i<f.nine.length;i++){if(f.nine[i].checked){s=s+eval(f.nine[i].value);}}
for(i=0;i<f.ten.length;i++){if(f.ten[i].checked){s=s+eval(f.ten[i].value);}}

if(s<21){t="That was poor";}
if(s>20 && s<41){t="That was ok";}
if(s>40 && s<61){t="a break even";}
if(s>60 && s<81){t="hmm u read the questions";}
if(s>80){t="ur a genious";}

alert("You Have Scored " + s + "% "+t)
}
</Script>

<form name="f">
<B>1. Question1</B>
<BR>
<BR>
<BR>
<B>2. Question2</B>
<BR>
<BR>
<BR>
<B>3. Question3</B>
<BR>
<BR>
<BR>
<B>4. Question4</B>
<BR>
<BR>
<BR>
<B>5. Question5</B>
<BR>
<BR>
<BR>
<B>6. Question6</B>
<BR>
<BR>
<BR>
<B>7. Question7</B>
<BR>
<BR>
<BR>
<B>8. Question8</B>
<BR>
<BR>
<BR>
<B>9. Question9</B>
<BR>
<BR>
<BR>
<B>10. Question10</B>
<BR>
<BR>