Skip to main content
October 19, 2009
Answered

How should I add Multiple choice answer to an object please?

  • October 19, 2009
  • 2 replies
  • 724 views

Hello Everyone,

I have declared an array which holds an object such as:

var myArr:Array = new Array({Question: 'Primary Colors Are?'});

How can I add the multiple choices to the object, please? These are the choices:

red, green, blue

orange, red, white,

purple, yellow, green,

white, black, blue

I certainly can create the Answers as:

var myArr:Array = new Array({ Question: 'Primary Colors Are?', Answer1: 'red, green, blue',

, Answer2: 'orange, red, white, Answer3: 'purple, yellow, green', Answer4: 'white, black, blue' });

What I would like to do is to be able to store all the answer choices within an array called AnsArr. Can I declare a new array within the same obejct such as AnsArr and push these choices to it?  I would highly appreciate your help.

Thanks.

This topic has been closed for replies.
Correct answer John_Hall

You could certainly do that and there's nothing wrong with that. You could have the question as element [0] and the array of potential answers as element [1]. I would typically use a database for this stuff but if the answers and questions don't change much, your method is fine, imho. You might also, however, consider storing a right/wrong bit with each answer so that the second element is an array of arrays in which the second level array is the distractor and its 'correctness.' That way, the answer will travel with the distractors. So, in short, nothing wrong with your method in my opinion.

2 replies

October 19, 2009

That should be done with XML.

<quiz>

     <question text="Primary Colors are?" answer="1">

          <choice>Red, Yellow, Pink</choice>

          <choice>Red, Green, Blue</choice>

          <choice>Blue, Orange, Black</choice>

     </question>

</quiz>

John_HallCorrect answer
Inspiring
October 19, 2009

You could certainly do that and there's nothing wrong with that. You could have the question as element [0] and the array of potential answers as element [1]. I would typically use a database for this stuff but if the answers and questions don't change much, your method is fine, imho. You might also, however, consider storing a right/wrong bit with each answer so that the second element is an array of arrays in which the second level array is the distractor and its 'correctness.' That way, the answer will travel with the distractors. So, in short, nothing wrong with your method in my opinion.

October 19, 2009

Thank you, John.