I have a series of check boxes. The user must select the ones that are predefined in an array. If they have all of the right ones selected, they continue, if they have one selected that shouldn’t, it fails.
That all works fine for me. My question is, if the user has none selected, allCorrect is true which it shouldn’t be. My logic is almost there, but needs some help…what should I do?
private var correctAnswers:Array = new Array("a","c");
private function onSubmit(event:MouseEvent):void
{
var allCorrect:Boolean = true;
for (var i:int = 0; i < options.length; i++)
{
var target = questionHolder.getChildByName("cb" + i);
if (target.selected == true)
{
if (correctAnswers.indexOf(target.label.substr(0,1).toLowerCase()) == -1)
{
//trace("wrong");
allCorrect = false;
}
else
{
//trace("correct");
}
}
}
trace(allCorrect);
}