Question counter for nested timeline #1251
-
Hi, I'm trying to add counter number as '(Question 1/5)' '(Question 2/5)' for each question. I found a possible solution here: https://groups.google.com/g/jspsych/c/MH9GFxhj4q8, but I'm not sure where to put the for loop. Here's my code and I think I put it in a wrong place because the
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi @Stella-xyl , Are you intending for each question to be on a separate page, or do you want all questions on a single page? |
Beta Was this translation helpful? Give feedback.
-
One way to do this is to have a variable that you use to track the question number across trials during the task, and use the current value of that variable as your question number in the prompt (instead of var timeline = []
var question_number = 1;
var trial = {
timeline_variables: [
{data: 'Q1'},
{data: 'Q2'},
{data: 'Q3'},
{data: 'Q4'},
{data: 'Q5'}
],
timeline: [
{
type: 'survey-text',
questions: function(){
return [{ prompt: '(Question ' + question_number + '/5)' + '<br>' + jsPsych.timelineVariable('data', true), columns: 6, required: true}]
},
button_label: 'submit',
data: jsPsych.timelineVariable('data'),
on_finish: function() {
question_number++;
}
}
]
};
timeline.push(trial); Is that what you wanted? |
Beta Was this translation helpful? Give feedback.
One way to do this is to have a variable that you use to track the question number across trials during the task, and use the current value of that variable as your question number in the prompt (instead of
i
). You can initialize this variable to 1 and increase it by 1 in the trial'son_finish
function.