Skip to content

Question counter for nested timeline #1251

Answered by becky-gilbert
Stella-xyl asked this question in Q&A
Discussion options

You must be logged in to vote

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's on_finish function.

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.timeli…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Stella-xyl
Comment options

@Stella-xyl
Comment options

Comment options

You must be logged in to vote
1 reply
@Stella-xyl
Comment options

Answer selected by Stella-xyl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants