D
djconner
I'm a total neophyte in Javascript, trying to hack something together
fast, and run into something that I can't understand at all.
Two loops appear in sequence. The idea is that arrQuestions consists
of the answers to each of 6 questions. Each is answered by a number,
0-5, and each number can only be used once.
So arrNumbers tracks whether a particular number was used as an
answer. arrNumbers[1] would be set to 'Used' if the user answered
"one" on any question.
(All values for arrNumbers are hard-coded to 'Not Used' before this
code runs.)
Loop 1 appears to work. Then I use Loop 2 to loop through arrNumbers
and look for values that are still equal to 'Not Used'. Not only does
this loop fail to work, it actually seems to RESET the values for
arrNumbers!
Am I making some incredibly stupid newbie error here? Have I missed
some fundamental law of JavaScript like you're not allowed to nest an
IF statement within a FOR loop for some damn reason?
I freely admit that I likely don't know what I'm doing, but any and
all help would be greatly appreciated!
for(q = 0; q < 6; q++){
r = arrQuestions[q];
alert(r);
arrNumbers[r]='Used';
alert(arrNumbers[r]);
}
for(s = 0; s < 6; s++){
if(arrNumbers='Not Used'){
alert(s);
alert(arrNumbers);
ArrayOK = false;
}
}
fast, and run into something that I can't understand at all.
Two loops appear in sequence. The idea is that arrQuestions consists
of the answers to each of 6 questions. Each is answered by a number,
0-5, and each number can only be used once.
So arrNumbers tracks whether a particular number was used as an
answer. arrNumbers[1] would be set to 'Used' if the user answered
"one" on any question.
(All values for arrNumbers are hard-coded to 'Not Used' before this
code runs.)
Loop 1 appears to work. Then I use Loop 2 to loop through arrNumbers
and look for values that are still equal to 'Not Used'. Not only does
this loop fail to work, it actually seems to RESET the values for
arrNumbers!
Am I making some incredibly stupid newbie error here? Have I missed
some fundamental law of JavaScript like you're not allowed to nest an
IF statement within a FOR loop for some damn reason?
I freely admit that I likely don't know what I'm doing, but any and
all help would be greatly appreciated!
for(q = 0; q < 6; q++){
r = arrQuestions[q];
alert(r);
arrNumbers[r]='Used';
alert(arrNumbers[r]);
}
for(s = 0; s < 6; s++){
if(arrNumbers
alert(s);
alert(arrNumbers
ArrayOK = false;
}
}