Feedback on the Survey-Text Type Trial #2396
-
Hello, I am Dusan and I am trying to develop a simple sequence recall test. var timeline = [];
var repeat_prac = false;
var practice_timeline = [
{
correct_response: {"Q0":"a"},
},
{
correct_response: {"Q0":"a"},
},
{
correct_response: {"Q0":"a"},
},
{
correct_response: {"Q0":"a"},
},
{
correct_response: {"Q0":"a"},
},
{
correct_response: {"Q0":"a"},
}
];
var instructions = {
type: 'html-button-response',
stimulus: 'Something',
choices: ['Next']
};
var practice_trial = {
type: 'survey-text',
questions: [
{prompt: 'Answer', required: true},
],
data: {
correct_response: jsPsych.timelineVariable('correct_response'),
trial_part: 'practice'
},
on_finish: function(data) {
var acc = false;
if (jsPsych.pluginAPI.compareKeys(data.correct_response, data.response)) {
acc = true;
}
data.accuracy = acc;
}
};
var feedback = {
type: 'html-keyboard-response',
stimulus: function() {
var feedback_text = '<span style="color:red;font-size:30px;">Incorrect.</span>';
var last_resp_acc = jsPsych.data.getLastTrialData().values()[0].accuracy;
if (last_resp_acc == true) {
feedback_text = '<span style="color:green;font-size:30px;">Correct!</span>'
}
return feedback_text;
},
choices: jsPsych.NO_KEYS,
trial_duration: 2000
};
var prac_procedure = {
timeline: [practice_trial, feedback],
timeline_variables: practice_timeline,
randomize_order: true
};
var repeat_prac_message = {
type: 'html-button-response',
stimulus: '<p>Not enough correct responses.</p>'+
'<p>Repeat everything.</p>',
choices: ['Yes, please']
};
var repeat_prac_conditional = {
timeline: [repeat_prac_message],
conditional_function: function() {
var last_prac_trials = jsPsych.data.get().filter({trial_part:'practice'}).last(practice_trial.length);
var n_correct = last_prac_trials.filter({accuracy: true}).count();
var prop_corr = n_correct/practice_trial.length;
if (prop_corr < 0.6) {
repeat_prac = true;
return true;
} else {
repeat_prac = false;
return false;
}
}
}
var instructions_prac_loop = {
timeline: [instructions, prac_procedure, repeat_prac_conditional],
loop_function: function() {
if (repeat_prac == true) {
return true;
} else {
return false;
}
}
}
timeline.push(instructions_prac_loop);
/* start the experiment */
var block = {
type: 'html-keyboard-response',
choices: ['n'],
stimulus: '<p>Press "a" to complete the experiment.</p>',
stimulus_width: 300,
on_finish: function(data) {
if (jsPsych.pluginAPI.compareKeys(data.response, 'a')) {
jsPsych.endExperiment('Success. You can exit.');
}
}
};
timeline.push(block);
jsPsych.init({
timeline: timeline,
show_preload_progress_bar: true,
message_progress_bar: "Progress",
show_progress_bar: true,
use_webaudio: false,
case_sensitive_responses: false,
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @dusannicolik92, I'm guessing you're using jsPsych v6.3? Do you see any errors in the console? It might also be helpful to see the output of I think the problem might be the use of the In your code, you're comparing two objects, and even if you extract the response string from the objects, there can be more than one character in the response (e.g. {
correct_response: 'a'
}
// ...
if (data.response.Q0 == data.correct_response) {
acc = true;
} And if you want to make sure that the comparison isn't case sensitive, you could call Does that work? BTW a lot of people seem confused about when to use the jsPsych |
Beta Was this translation helpful? Give feedback.
Hi @dusannicolik92, I'm guessing you're using jsPsych v6.3? Do you see any errors in the console? It might also be helpful to see the output of
console.log(data)
in your response trial, just to double check the format of the data.I think the problem might be the use of the
jsPsych.pluginAPI.compareKeys
function here. That function is intended to compare individual key press strings, e.g. 'a', 'l'. (And the only reason this function exists is so that two key presses can be compared in a case sensitive or insensitive way, depending on the experiment settings).In your code, you're comparing two objects, and even if you extract the response string from the objects, there can be more than on…