-
Hi, Using codes from previous discussions, I have tried to build a timed text survey. Below are the relevant parts of the code. Thank you very much in advance for your help. var timeline = [];
var time_limit = 5000;
var start_time;
var end_test_timer;
var trial_count1 = 0;
var n_trials1 = test_stimuli1.length;
var test_stimuli1 = [
{stimulus:'31', liste:'Ajouter', correct:'34'},
{stimulus:'90', liste:'Ajouter', correct:'93'},
{stimulus:'18', liste:'Ajouter', correct:'21'},
{stimulus:'23', liste:'Ajouter', correct:'26'},
];
var test1 = {
type: 'survey-text',
questions: [
{prompt: jsPsych.timelineVariable('stimulus'), name:'resp'},
],
autocomplete : false,
on_load: function() {
trial_count1++;
// we need to set up the timer to end the current timeline after a certain duration, but only on the first trial
if (trial_count1 == 1) {
start_time = performance.now();
var end_test_timer = setTimeout(function() {
// this stuff is just for testing
var end_time = performance.now();
var elapsed_time = end_time - start_time;
console.log("elapsed time: ", elapsed_time);
// this function is all you need to end the current timeline
jsPsych.endCurrentTimeline();
// this function ends the current trial
jsPsych.finishTrial({status: "ended early"});
}, time_limit);
}
},
on_finish: function(data) {
data.correct=jsPsych.timelineVariable('correct');
data.liste=jsPsych.timelineVariable('liste');
var acc = 0;
var response = jsPsych.data.getLastTrialData().values()[0].response.resp;
if (response == data.correct){
acc = 1;
}
data.acc=acc;
// we also need to cancel the setTimeout timer if the person gets all the way through the timeline before
// time_limit is reached, otherwise endCurrentTimeline will fire during the next timeline - not good!!
if (trial_count1 == n_trials1) {
clearTimeout(end_test_timer);
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The var response = jsPsych.data.getLastTrialData().values()[0].response.resp; you can just use var response = data.response.resp; |
Beta Was this translation helpful? Give feedback.
The
data
parameter in theon_finish()
function will already contain the response of the participant, so instead of:you can just use