Reply To: About keyresponse in Question

PennController for IBEX Forums Support About keyresponse in Question Reply To: About keyresponse in Question

#9615
Jeremy
Keymaster

Hi Karen,

When the Question controller’s as parameter is not an array of strings, but an array of pairs of strings (whose first member represents a key and the second member is the printed answer) you cannot pass a string as hasCorrect: you need to either pass true, in which case it means the first answer is the correct one, or a integer between 0 and the length of the array minus one, so in your case where you have two answers, either 0 (first answer in the array, selectable by pressing F) or 1 (second answer in the array, selectable by pressing J)

Now, there is a subtlety, which is that values fetched from the table in Template are interpreted as strings by default, so even if you list 0s and 1s in your “Corr” column, they’ll still be interpreted as strings when you reference row.Corr. The solution is to force a coercion into an integer, using parseInt: newController("Question", {q: "Is it reasonable?", as: [["F","reasonable"], ["J","unreasonable"]], hasCorrect: parseInt(row.Corr), randomOrder: false})

Jeremy