...

View Full Version : I need some help :)



aaweth
06-28-2006, 09:13 AM
Hey there , I have been trying to work out how to get a quiz working but the button doesn't work and I don't know where to put the links to my results page within the java script... here is the script at the moment...

<html>

<head>

<title>LOTR Quiz - The Hobbit Round</title>
<font face="verdana" size="1">
<SCRIPT LANGUAGE="JavaScript">
<!--
function process()
{
var Excellent = 1;
var notbad = 2;
var morework = 3;
var tryagain = 4;
var f = document.f;
var i = 0;

for (i = 0; i < f.one.length; i++) if (f.one[i].checked) value = f.one[i].value;
if (value == "3") { Southern Star ++; }
if (value == "2") { Old Toby++; }
if (value == "1") { Longbottom Leaf ++; }
if (value == "4") { Southlinch++; }


for (i = 0; i < f.two.length; i++) if (f.two[i].checked) value = f.two[i].value;
if (value == "1") { Merry++; }
if (value == "2") { Pippin++; }
if (value == "3") { Bilbo++; }
if (value == "4") { Sam++; }

for (i = 0; i < f.three.length; i++) if (f.three[i].checked) value = f.three[i].value;
if (value == "1") { Tobold Hornblower++; }
if (value == "2") { Rosie Cotton++; }
if (value == "3") { Bungo Baggins++; }
if (value == "4") {Lobelia Bracegirdle++; }

for (i = 0; i < f.four.length; i++) if (f.four[i].checked) value = f.four[i].value;
if (value == "3") { Pipe-weed Grower++; }
if (value == "2") { Chef In The Green Dragon++; }
if (value == "1") { Mill Operator++; }
if (value == "4") { Mushroom Picker++; }

for (i = 0; i < f.five.length; i++) if (f.five[i].checked) value = f.five[i].value;
if (value == "3") { 17++; }
if (value == "2") { 20++; }
if (value == "1") { 33++; }
if (value == "4") { 55++; }


var out = "Excellent";
i = Excellent;
if (Excellent > i) { out = "Excellent"; i = Excellent; }
if (Notbad > i) { out = "NotBad"; i = Notbad; }
if (Morework > i) { out = "Morework"; i = Morework; }
if (Tryagain > i) { out = "Tryagain"; i = Tryagain; }

location.href = out + "http://www.freewebs.com/elvenwonder/Result1.html";
}
function err(msg, url, line)
{
location.href = "error.html";
}
//window.onerror = err;
// -->
</SCRIPT>

</head>

<body bgcolor=ffffff>

<center>

<font size=5><b>LOTR Quiz - The Hobbit Round</b></font><br><br><br><br>

<table width=525 border=0><tr><td>

<form name="The Hobbit Round">
Number 1: What type of Hobbit Tobbacco goes by the elvish name of Nicotiana? <br>
<input type="radio" name="one" value="2"> Old Toby<br>
<input type="radio" name="one" value="3"> Southern Star<br>
<input type="radio" name="one" value="1"> Longbottom Leaf<br>
<input type="radio" name="one" value="4"> Southlinch<br>

<br><br><br>

Number 2: Who wrote the book called “Herblore of the Shire’?<br>
<input type="radio" name="two" value="1"> Merry<br>
<input type="radio" name="two" value="2"> Pippin<br>
<input type="radio" name="two" value="3"> Bilbo<br>
<input type="radio" name="two" value="4"> Sam<br>

<br><br><br>

Number 3: Who was the first Hobbit to grow pipe-weed? <br>
<input type="radio" name="three" value="1"> Tobold Hornblower<br>
<input type="radio" name="three" value="2"> Rosie Cotton<br>
<input type="radio" name="three" value="3"> Bungo Baggins<br>
<input type="radio" name="three" value="4"> Lobelia Bracegirdle<br>

<br><br><br>

Number 4: Who was Ted Sandyman? <br>
<input type="radio" name="four" value="1"> Mill Operator<br>
<input type="radio" name="four" value="2"> Pipe-weed Grower<br>
<input type="radio" name="four" value="3"> Chef in the Green Dragon<br>
<input type="radio" name="four" value="4"> Mushroom Picker<br>

<br><br><br>

Number 5: How old do you have to be to be considered an adult Hobbit? <br>
<input type="radio" name="five" value="2"> 20<br>
<input type="radio" name="five" value="1"> 33<br>
<input type="radio" name="five" value="3"> 17<br>
<input type="radio" name="five" value="4"> 55<br>

<br><br><br>

<input type="button" value=" Click for results " onclick="process();"><br><br><br>

</td></tr></table>
<center>I learned how to make the quiz @ <a href="http://ticklez.net" target="_blank">ticklez.net</a>.</center>
</body>
</html>

and here are the links to my results pages

http://www.freewebs.com/elvenwonder/Result1.html (aka excellent)
http://www.freewebs.com/elvenwonder/Result2.html (aka notbad)
http://www.freewebs.com/elvenwonder/Result3.html (aka morework)
http://www.freewebs.com/elvenwonder/Result4.html (aka tryagain)

I would be so greatfulif somebody could help me out with this!!

Kayleigh

~x~

CSTruter
07-04-2006, 07:51 AM
This is what was wrong with the code:

First off, some terminology for understanding errors better:
Syntax error 1: Variable Names cant contain spaces.
Syntax error 2: Variable Names cant start with a number or be a number.

Secondly, Logic errors:
Line 10-14; 15 - 19; 20 -24; 25-29; 30-34;
Incrementing variables which isnt used anywhere else.

Line 37-41;
Will generate a 404 error, page not found, hence variables assigned to front of URL

There is quite a few other errors as well, but this is the basic errors.

<html>

<head>

<title>LOTR Quiz - The Hobbit Round</title>
<font face="verdana" size="1">
<SCRIPT LANGUAGE="JavaScript">
<!--
1. function process()
2. {
3. var Excellent = 1;
4. var notbad = 2;
5. var morework = 3;
6. var tryagain = 4;
7. var f = document.f;
8. var i = 0;
9.
10. for (i = 0; i < f.one.length; i++) if (f.one[i].checked) value = f.one[i].value;
11. if (value == "3") { Southern Star ++; } // Syntax Error 1
12. if (value == "2") { Old Toby++; } // Syntax Error 1
13. if (value == "1") { Longbottom Leaf ++; } // Syntax Error 1
14. if (value == "4") { Southlinch++; }


15. for (i = 0; i < f.two.length; i++) if (f.two[i].checked) value = f.two[i].value;
16. if (value == "1") { Merry++; }
17. if (value == "2") { Pippin++; }
18. if (value == "3") { Bilbo++; }
19. if (value == "4") { Sam++; }

20. for (i = 0; i < f.three.length; i++) if (f.three[i].checked) value = f.three[i].value;
21. if (value == "1") { Tobold Hornblower++; } // Syntax Error 1
22. if (value == "2") { Rosie Cotton++; } // Syntax Error 1
23. if (value == "3") {Bungo Baggins++; } // Syntax Error 1
24. if (value == "4") {Lobelia Bracegirdle++; } // Syntax Error 1

25. for (i = 0; i < f.four.length; i++) if (f.four[i].checked) value = f.four[i].value;
26. if (value == "3") { Pipe-weed Grower++; } // Syntax Error 1
27. if (value == "2") { Chef In The Green Dragon++; } // Syntax Error 1
28. if (value == "1") { Mill Operator++; } // Syntax Error 1
29. if (value == "4") { Mushroom Picker++; } // Syntax Error 1

30. for (i = 0; i < f.five.length; i++) if (f.five[i].checked) value = f.five[i].value;
31. if (value == "3") { 17++; }// Syntax Error 2
32. if (value == "2") { 20++; }// Syntax Error 2
33. if (value == "1") { 33++; }// Syntax Error 2
34. if (value == "4") {55++; }// Syntax Error 2


35. var out = "Excellent";
36. i = Excellent;
37. if (Excellent > i) { out = "Excellent"; i = Excellent; }
38. if (Notbad > i) { out = "NotBad"; i = Notbad; }
39. if (Morework > i) { out = "Morework"; i = Morework; }
40. if (Tryagain > i) { out = "Tryagain"; i = Tryagain; }

41. location.href = out + "http://www.freewebs.com/elvenwonder/Result1.html";
42. }
43. function err(msg, url, line)
44. {
45. location.href = "error.html";
46. }
//window.onerror = err;
// -->
</SCRIPT>

</head>

<body bgcolor=ffffff>

<center>

<font size=5><b>LOTR Quiz - The Hobbit Round</b></font><br><br><br><br>

<table width=525 border=0><tr><td>

<form name="The Hobbit Round">
Number 1: What type of Hobbit Tobbacco goes by the elvish name of Nicotiana? <br>
<input type="radio" name="one" value="2"> Old Toby<br>
<input type="radio" name="one" value="3"> Southern Star<br>
<input type="radio" name="one" value="1"> Longbottom Leaf<br>
<input type="radio" name="one" value="4"> Southlinch<br>

<br><br><br>

Number 2: Who wrote the book called “Herblore of the Shire’?<br>
<input type="radio" name="two" value="1"> Merry<br>
<input type="radio" name="two" value="2"> Pippin<br>
<input type="radio" name="two" value="3"> Bilbo<br>
<input type="radio" name="two" value="4"> Sam<br>

<br><br><br>

Number 3: Who was the first Hobbit to grow pipe-weed? <br>
<input type="radio" name="three" value="1"> Tobold Hornblower<br>
<input type="radio" name="three" value="2"> Rosie Cotton<br>
<input type="radio" name="three" value="3"> Bungo Baggins<br>
<input type="radio" name="three" value="4"> Lobelia Bracegirdle<br>

<br><br><br>

Number 4: Who was Ted Sandyman? <br>
<input type="radio" name="four" value="1"> Mill Operator<br>
<input type="radio" name="four" value="2"> Pipe-weed Grower<br>
<input type="radio" name="four" value="3"> Chef in the Green Dragon<br>
<input type="radio" name="four" value="4"> Mushroom Picker<br>

<br><br><br>

Number 5: How old do you have to be to be considered an adult Hobbit? <br>
<input type="radio" name="five" value="2"> 20<br>
<input type="radio" name="five" value="1"> 33<br>
<input type="radio" name="five" value="3"> 17<br>
<input type="radio" name="five" value="4"> 55<br>

<br><br><br>

<input type="button" value=" Click for results " onclick="process();"><br><br><br>

</td></tr></table>
<center>I learned how to make the quiz @ <a href="http://ticklez.net" target="_blank">ticklez.net</a>.</center>
</body>
</html>

Here is working code:

Please note that the whole process function, will be better of running server side for a few reasons, sooo rather make the process script php or asp or something, but for this example, i am doing it in javascript.

I dont know the answers to the quiz, so i simply gave it some dummy answers, that can be changed, by giving the answers array the correct answers.



<html>
<head>
<title>LOTR Quiz - The Hobbit Round</title>

<script language="JavaScript">

function process()
{
correct=0;
answers = new Array();
answers = [0,2,1,3,0];

for (i=0; i < answers.length;i++)
{
if(document.getElementsByName('Q'+i)[answers[i]].checked)
{
correct++;
}
}

switch(correct)
{
case 0:
case 1:
location.href='http://www.freewebs.com/elvenwonder/Result4.html';
break;
case 2:
location.href='http://www.freewebs.com/elvenwonder/Result3.html';
break;
case 3:
case 4:
location.href='http://www.freewebs.com/elvenwonder/Result2.html';
break;
case 5:
location.href='http://www.freewebs.com/elvenwonder/Result1.html';
break;
}
}

</script>

</head>
<body bgcolor="ffffff">
<center>
<font size="5"><b>LOTR Quiz - The Hobbit Round</b></font><br>
<br>
<br>
<br>
<table width="525" border="0">
<tr>
<td>
Number 1: What type of Hobbit Tobbacco goes by the elvish name of Nicotiana?
<br>
<input type="radio" name="Q0" value="1">Old Toby<br>
<input type="radio" name="Q0" value="2">Southern Star<br>
<input type="radio" name="Q0" value="3">Longbottom Leaf<br>
<input type="radio" name="Q0" value="4">Southlinch<br>
<br><br><br>
Number 2: Who wrote the book called “Herblore of the Shire’?<br>
<input type="radio" name="Q1" value="1">Merry<br>
<input type="radio" name="Q1" value="2">Pippin<br>
<input type="radio" name="Q1" value="3">Bilbo<br>
<input type="radio" name="Q1" value="4">Sam<br>
<br><br><br>
Number 3: Who was the first Hobbit to grow pipe-weed?
<br>
<input type="radio" name="Q2" value="1">Tobold Hornblower<br>
<input type="radio" name="Q2" value="2">Rosie Cotton<br>
<input type="radio" name="Q2" value="3">Bungo Baggins<br>
<input type="radio" name="Q2" value="4">Lobelia Bracegirdle<br>
<br><br><br>
Number 4: Who was Ted Sandyman?
<br>
<input type="radio" name="Q3" value="1">Mill Operator<br>
<input type="radio" name="Q3" value="2">Pipe-weed Grower<br>
<input type="radio" name="Q3" value="3">Chef in the Green Dragon<br>
<input type="radio" name="Q3" value="4">Mushroom Picker<br>
<br><br><br>
Number 5: How old do you have to be to be considered an adult Hobbit?
<br>
<input type="radio" name="Q4" value="1">20<br>
<input type="radio" name="Q4" value="2">33<br>
<input type="radio" name="Q4" value="3">17<br>
<input type="radio" name="Q4" value="4">55<br>
<br><br><br>
<input type="button" value=" Click for results " onclick="process()"><br>
<br>
<br>
</td>
</tr>
</table>
</body>
</html>



The code i gave is pretty easy to understand, let me know if anything is unclear.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum