Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
JsPsych set timer for survey-text trial

Using JsPsych, I need to set a 10s timer for each question prompt so that when time is up, the trial will end immediately and go to next question. Here's my code:

var time_limit = 10000;
var start_time2;
var end_test_timer;
var trial_count = 0;
var n_trials = questions.length;
var counter2 = 1;

var ListB_test_trial = {
    timeline_variables: [ 
        {data: questions[0], q: questions[0]}, 
        {data: questions[1], q: questions[1]},
    ],
    timeline: [ {
        timeline: [
            {type: 'survey-text',
            questions: function (){
                return [{prompt: '(Q' + counter2 + '/15) ' + jsPsych.timelineVariable('q', true), columns: 25, required: true}]
            },
            button_label: ['submit'],
            data: jsPsych.timelineVariable('data'), 
            preamble:  '<p style="font-size: 15px; line-height: 12px;">[Please answer using your own knowledge and best guess. Type your answer and press submit.]</p>',
            on_load: function() {
                trial_count++;
                // we need to set up the timer to end the current timeline after a certain duration, but only on the first trial
                if (trial_count > 0) {
                    start_time2 = 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_time2;
                        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() {
                counter2++;
                // 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_count == n_trials) {
                    clearTimeout(end_test_timer);
                }
                    }
            }
        ], 
        randomize_order: true,
    }, get_ready ]
};
timeline.push(ListB_test_trial);

I got the code from here: https://github.com/jspsych/jsPsych/discussions/1146 but do not know how to adapt it. So far, instead of 10s for each question, the total time limit for answering all of the questions is 10s.

Thanks!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda