survey text data. #1987
-
Hi, I am trying to add a "correct_response" function to the data section of my trials. Here is what I've got: const POD_1_response = {
type: 'survey-text',
questions: [
{prompt: "What word was she about to say? (no caps!)"}
],
post_trial_gap: 500,
data: {condition: 'Bucket', correct_response: "bucket"},
on_finish: function(data) {
data.correct = jsPsych.pluginAPI.compareKeys(data.response, data.correct_response);
}
} and here is what the data display shows: "rt": 4356,
"response": {
"Q0": "bucket"
},
"condition": "Bucket",
"correct_response": "bucket",
"trial_type": "survey-text",
"trial_index": 5,
"time_elapsed": 16094,
"internal_node_id": "0.0-4.0-1.0" How do i got the correct_response function to recognize the survey-text responses? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @rbruno1, there are two issues here. First, the So try this in your trial's data.correct = data.response.Q0 == data.correct_response; And here's another tip: JavaScript has the data.correct = data.response.Q0.toLowerCase() == data.correct_response; And there are some other fancy things you could do with JavaScript, like remove spaces using I hope this helps. |
Beta Was this translation helpful? Give feedback.
Hi @rbruno1, there are two issues here. First, the
compareKeys
function is just meant for checking whether two keyboard key presses are the same, so I wouldn't use that function to compare two text responses. Second, to access the participant's response in theon_finish
function, you'll need to usedata.response.Q0
, becausedata.response
is an object that contains key/value pairs for each question, and you're trying to access the response to the first (only) question, which is automatically called "Q0".So try this in your trial's
on_finish
function:And here's another tip: JavaScript has the
toLowerCase
function for converting str…