I am trying to figure out the best way to dynamically build variables. I have a database that looks like this:
One record:
ans1
ans2
ans3
res1
res2
res3
I have a function that checks the answer against the button the user pressed.
checkAnswer(q, a, $event) {
if(a == q.correct){
this.correctanswer = q.success
}
}
The variable 'a' is either 1, 2 or 3
I would like the code to look something like this:
this.correctanswer = q.res+a
However, this is not working. How can I look up the appropriate response based on the answer the user chooses? So if the user presses answer 1 they see res1 and so on.
q
look like?this
is in reference to what? Please show a little more code. I think its probably something real simple.this
for now as it is not necessary for my request[]
notation for variable property names....q['res'+a]