Copy link to clipboard
Copied
I have a quiz created in Flex using Spark forms, with a series of questions which are a group of radio buttons. When the user clicks "next", I get the value of the selected radio button in the group.
What I need to do is keep track of these values; at the end of the quiz I will need to see which value was chosen the most. So if the user mostly picked the questions with a "3" value, I can display a summary based on that, e.g. "You mostly chose type 3 answers".
I was thinking about having an int variable for every choice (there are 5), and incrementing the appropriate variable when the user clicks "next", as in
private function enterScore(i:int):void {
switch (i){
case 1:
num1++;
break;
But this seems unwieldy. Can anyone suggest a better way?
I also will need to compare the 5 tallies for which one was chosen the most... Any ideas on that?
Thanks.
Copy link to clipboard
Copied
an associative array would be pretty straight-forward:
var answerObj:Object={};
.
.
.
.
if(answerObj[radiogroupvalue]){
answerObj[radiogroupvalue]++;
} else {
answerObj[radiogroupvalue]=1;
}