-
Hi. So my experiment plays a word, and the participant has to write the word they heard. I have implemented a feedback trial, but i would like to loop the trial if the participant guesses wrong. here is what i've got. Just tell me where i went wrong. The loop function isn't executing. const practice_trial_3 = {
timeline: [
{type: 'audio-keyboard-response',
stimulus: 'GatingStimuli_Dollar.wav',
response_allowed_while_playing: false,
trial_ends_after_audio: true,
post_trial_gap: 250
},
{ type:'html-button-response',
stimulus: ["Press OK to move on, or Listen again to replay the sound"],
choices: ['OK', 'Listen again'],
post_trial_gap: 500,
on_start: function(trial) {
if (repeated) {
trial.choices = ['OK'];
}
}
}],
loop_function: function(data){
if(data.values()[1].response == 1
&& !repeated){
repeated = true;
return true;
} else {
repeated = false;
return false;
}
}
};
const practice_response_trial_3 = {
type: 'survey-text',
questions: [
{prompt: "What word was she about to say? If you don't know or didnt hear, then type NR for no response"}
],
post_trial_gap: 500,
data: {
task: 'response',
correct_response: 'dollar'
},
on_finish: function(data) {
data.correct = data.response.Q0.toLowerCase() == data.correct_response;
},
}
**const practice_feedback_3 = {
type: 'html-button-response',
choices: ['Next'],
stimulus: function(){
var last_trial_correct = jsPsych.data.get().last(1).values()[0].correct;
if(last_trial_correct){
return "<p>Correct! You are ready for the real experiment.</p>";
} else {
return "<p>You answered incorrectly. Let's try that one again.</p>";
}
},
loop_function: function(data){
if(last_trial_correct){
return true;
} else {
return false;
}
}
}** |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
so i got it to work, but the loop only executes once. how do i make it loop until there is a correct response? here is the updated code: const practice_trial_3 = {
timeline: [
{type: 'audio-keyboard-response',
stimulus: 'GatingStimuli_Dollar.wav',
response_allowed_while_playing: false,
trial_ends_after_audio: true,
post_trial_gap: 250
},
{ type:'html-button-response',
stimulus: ["Press OK to move on, or Listen again to replay the sound"],
choices: ['OK', 'Listen again'],
post_trial_gap: 500,
on_start: function(trial) {
if (repeated) {
trial.choices = ['OK'];
}
}
}]
}
const practice_response_trial_3 = {
type: 'survey-text',
questions: [
{prompt: "What word was she about to say? If you don't know or didnt hear, then type NR for no response"}
],
post_trial_gap: 500,
data: {
task: 'response',
correct_response: 'dollar'
},
on_finish: function(data) {
data.correct = data.response.Q0.toLowerCase() == data.correct_response;
},
}
const practice_feedback_3 = {
type: 'html-button-response',
choices: ['Next'],
stimulus: function(){
// The feedback stimulus is a dynamic parameter because we can't know in advance whether
// the stimulus should be 'correct' or 'incorrect'.
// Instead, this function will check the accuracy of the last response and use that information to set
// the stimulus value on each trial.
var last_trial_correct = jsPsych.data.get().last(1).values()[0].correct;
if(last_trial_correct){
return "<p>Correct! You are ready for the real experiment.</p>"; // the parameter value has to be returned from the function
} else {
return "<p>You answered incorrectly. Let's try that one again.</p>"; // the parameter value has to be returned from the function
}
}
}
const practice_feedback_3_loop = {
timeline:[practice_trial_3,practice_response_trial_3,practice_feedback_3],
loop_function: function(data){
var last_trial_correct = jsPsych.data.get().first(1).values()[0].correct;
if(last_trial_correct){
return true;
} else {
return false;
}}} |
Beta Was this translation helpful? Give feedback.
-
FYI, I've edited your posts to make the code easier to read. You need to use 3 backticks (`) rather than single quotes (') to get the nice code formatting. See here: #1113 😃 |
Beta Was this translation helpful? Give feedback.
so i got it to work, but the loop only executes once. how do i make it loop until there is a correct response? here is the updated code: