Reputation: 235
I have an if statement that does not seem to work for my quiz, it's in AS2.
var check_answer_num:Number = (answer_num+1);
var tmp_answer:String = xml_engine.firstChild.childNodes[quiz_current].childNodes[1].firstChild;
var tmp_user_answer:String = xml_engine.firstChild.childNodes[quiz_current].childNodes[check_answer_num].firstChild;
if(tmp_answer==tmp_user_answer) {
trace("YES");
} else {
trace("NO");
}
When I test the quiz it outputs NO for every answer even if it is correct. Not sure if it's a defining vars problem?
Thanks.
Upvotes: 0
Views: 361
Reputation: 19635
I think your XML traversal may be amiss based on the sample XML that you gave.
Here's your XML (just for clarity):
<Quiz>
<Question>
<QText>Who is the main character?</QText>
<QAns>Brad Smith</QAns>
<Option>Al Ahkmed Zahid</Option>
<Option>Brad Smith</Option>
<Option>Dinah Soares</Option>
<Option>Jack Knoff</Option>
</Question>
<Question>
<QText>What was Brad Smith originally?</QText>
<QAns>A Homeless Guy</QAns>
<Option>A Homeless Guy</Option>
<Option>A Church Minister</Option>
<Option>A Homeless Guy</Option>
<Option>A Hippy</Option>
</Question>
</Quiz>
Now, here's your declaration of tmp_answer
:
var tmp_answer:String = xml_engine.firstChild.childNodes[quiz_current].childNodes[1].firstChild;
Assuming that xml_engine
is the entire doc represented above, xml_engine.firstChild
is the first <Question>
node, which I don't think is what you want.
Try this:
var tmp_answer:String = xml_engine.childNodes[quiz_current].childNodes[1].firstChild
That should give you "Brad Smith" for the first question
Upvotes: 1