I am making a quiz. There are a series of questions (" i " represents each question starting with " 0 ") with a possibility of up to 6 answers for each question (selected with radio buttons). There are a series of variables to hold the user’s answer (all ready initialized) called “userAnswer0” for the first answer, “userAnswer1” for the second answer, and so forth.
Everytime the person selects the “next button”, " i " increments by one. I can’t see what is wrong with my code but when I trace the user’s answers variables, I get nothing.
var i:Number = 0;
radioBtn0.onPress = function() {
userAnswer.text = “A”; // I have tried this*
//this[“userAnswer” + i] = “A”; // and this but neither work
}
radioBtn1.onPress = function() {
this[“userAnswer” + i] = “B”;
}
radioBtn2.onPress = function() {
this[“userAnswer” + i] = “C”;
}
radioBtn3.onPress = function() {
this[“userAnswer” + i] = “D”;
}
radioBtn4.onPress = function() {
this[“userAnswer” + i] = “E”;
}
radioBtn5.onPress = function() {
this[“userAnswer” + i] = “F”;
}
Any thoughts? Also, if there is a cleaner way of typing the code above, I would love to hear it as well but it isn’t necessary.