Click to See Complete Forum and Search --> : what is wrong with my script


scottec
02-26-2003, 02:04 PM
what i want is if you get one wrong you go to alert.htm and if you get them all right you go to home.htm








<script language=javascript>

questions = new Array("who gave frodo the one ring ?:",
"who did sam talk about often:","what color did gandoulf origonally wear:","what color did the ring wraiths wear:",
"who is an evil wizard saruman or saruon:","Quick beam was a tree ---:","who sent the felloship of the rings:",
"what was perigins last name:","was a hobbit turned bad:","aragorns other name:");

answers = new Array("bilbo","gaffer","grey","black","saruman","ent","elrond","took","gollum","strider");
x=0;
correct=0;
incorrect=0;
password=null;
do
{
password=prompt(questions[x],"")
if(password!=null && password.toLowerCase()==answers[x])

{
correct++;
}else{
incorrect++;
}
x++;

} while(x<questions.length)
if (incorrect != "1","2","3","4","5","6","7","8","9","10") {
location.href= "alert.htm";
}

if (location.href !="alert.htm") {
location.href= "home.htm";
}

</script>

AdamBrill
02-26-2003, 02:29 PM
The problem is in your if command at the bottom. You have:

if (incorrect != "1","2","3","4","5","6","7","8","9","10") {
location.href= "alert.htm";
}

if (location.href !="alert.htm") {
location.href= "home.htm";
}

When it should be:

if(incorrect !=1 && incorrect !=2 && incorrect != 3 && incorrect != 4)
And so on... The other thing is right now it will take them to alert.htm if they got them all right, and to home.htm if they got some wrong. I think this is what you want:

if (incorrect != 0) {
location.href= "alert.htm";
}else{
location.href= "home.htm";
}

scottec
02-26-2003, 03:35 PM
this is my script now but there is still somthing wrong












<script language=javascript>

questions = new Array("who gave frodo the one ring ?:",
"who did sam talk about often:","what color did gandoulf origonally wear:","what color did the ring wraiths wear:",
"who is an evil wizard saruman or saruon:","Quick beam was a tree ---:","who sent the felloship of the rings:",
"what was perigins last name:","was a hobbit turned bad:","aragorns other name:");

answers = new Array("bilbo","gaffer","grey","black","saruman","ent","elrond","took","gollum","strider");
x=0;
correct=0;
incorrect=0;
password=null;
do
{
password=prompt(questions[x],"")
if(password!=null && password.toLowerCase()==answers[x])

{
correct++;
}else{
incorrect++;
}
x++;

} while(x<questions.length)
if(incorrect !=1 && incorrect !=2 && incorrect != 3 && incorrect != 4 && incorrect != 5 && incorrect != 6 && incorrect != 7 && incorrect != 8 && incorrect != 9 && incorrect != 10 && incorrect)
{
location.href= "alert.htm";
}else{
location.href= "home.htm";
}

</script>

Charles
02-26-2003, 03:54 PM
if(incorrect !=1 && incorrect !=2 && incorrect != 3 && incorrect != 4 && incorrect != 5 && incorrect != 6 && incorrect != 7 && incorrect != 8 && incorrect != 9 && incorrect != 10 && incorrect)
{
location.href= "alert.htm";
}else{
location.href= "home.htm";
}

Would be better written:

if (!{1:1, 2:1, 3:1, 4:1, 5:1, 6:1, 7:1, 8:1, 9:1, 10:1} [incorrect]) {location.href='alert.htm'} else {location.href='home.htm'};

scottec
02-26-2003, 04:03 PM
now my coding looks like this but right or wrong it sends me to home.htm when you get one wrong it should send you to alert.htm





<script language=javaScript>

questions = new Array("who gave frodo the one ring ?:",
"who did sam talk about often:","what color did gandoulf origonally wear:","what color did the ring wraiths wear:",
"who is an evil wizard saruman or saruon:","Quick beam was a tree ---:","who sent the felloship of the rings:",
"what was perigins last name:","was a hobbit turned bad:","aragorns other name:");

answers = new Array("bilbo","gaffer","grey","black","saruman","ent","elrond","took","gollum","strider");
x=0;
correct=0;
incorrect=0;
password=null;
do
{
password=prompt(questions[x],"")
if(password!=null && password.toLowerCase()==answers[x])

{
correct++;
}else{
incorrect++;
}
x++;

} while(x<questions.length)
if (!{1:1, 2:1, 3:1, 4:1, 5:1, 6:1, 7:1, 8:1, 9:1, 10:1} [incorrect])
{location.href='alert.htm'}
else {location.href='home.htm'};


</script>


it really looks like it should work

Charles
02-26-2003, 04:26 PM
<script type="text/javascript">
<!--
questions = {"who gave frodo the one ring ?:" : "bilbo",
"who did sam talk about often:" : "gaffer", "what color did gandoulf origonally wear:" : "grey", "what color did the ring wraiths wear:" : "black",
"who is an evil wizard saruman or saruon:" : "saruman", "Quick beam was a tree ---:" : "ent", "who sent the fellowship of the rings:" : "elrond",
"what was perigins last name:" : "took", "was a hobbit turned bad:" : "gollum", "aragorns other name:" : "strider"}

var incorrect = false

for (q in questions) {
var answer = prompt(q,'');
if (answer.toLowerCase() != questions[q]) incorrect = true;
};

if (incorrect) {alert("location.href='alert.htm'")} else {alert("location.href='home.htm'")};

// -->
</script>

scottec
02-27-2003, 09:12 AM
thanks man i got it figured out thanks evrybody i ended up using a little from evry body thanks

this is the final code


my page watch out for alert.htm (http://www.angelfire.com/theforce/scottec/billbo.htm)


thanks

for non lord of the rings fans here are the answers

"billbo","gaffer","grey","black","saruman","ent","elrond","took","gollum","strider"