Response time not getting recorded through JS | XM Community
Skip to main content

Hello,

 In my project, the response time is not getting consistently recorded in the corresponding embedded variable. If I run it 10 times, it gets recorded 6/10 times for example. What am I doing wrong?

 

I am trying to create an interactive “game” using qualtrics. The rules of the game are the following:

There is a button that I call Invest. If the survey-taker (call her S) clicks on the button first and before 10 seconds, the button disappears and she gets $x. The program itself might click that button, and if it does it first and before 10 seconds, the button disappears too, and S gets $y. If neither click by 10 seconds, S gets $z.

Thus, I need a way to randomly generate the time when the program clicks the button, I do it by calling an embedded variable called ext1. And I want a way to measure when S clicks the button. I have pre-defined response time embedded variables RT1, RT2, etc for each iteration of the game, and I am trying to save the response times there.

Here is my attempt at it using JS.

 

Qualtrics.SurveyEngine.addOnReady(function()

    // Somehow, the response time is not being recorded consistently in other iterations
    
    // We start by recording the time at which the page loads
    var starttime = new Date().getTime();
    
    this.hideNextButton(); // ensure that the subjects cannot force to next screen
    this.clickNextButton.delay(15); // each round lasts 15 seconds, 5 seconds buffer time
    
    var btn = document.getElementById('btn');    
    var t=Qualtrics.SurveyEngine.getEmbeddedData( 'ext1');
    
    /* Remove Invest button on click*/
    btn.onclick = function () {
        this.remove();
        var endtime = new Date().getTime();
        var RT = endtime - starttime; // Response time
        

         Qualtrics.SurveyEngine.addEmbeddedData("RT" + Number("${lm://Field/1}"), RT);  
          
        document.getElementById("feedback").innerHTML = "Please wait for this round to end."; // show text

        
        
    }
        
    
    
    
        /* The setTimeout() method executes a block of code after the specified time. 
        The method executes the code only once.
        Goal: Remove Invest button externally using setTimeout function*/    
    
        setTimeout(function(){ 
      
              document.getElementById('btn').style.display ='none'; //remove button
              document.getElementById("feedback").innerHTML = "Please wait for this round to end"; // show text
              
              }
                   ,t);   // do it after time t
    
    
    
                    setTimeout(function(){ 
      
                              document.getElementById("feedback").innerHTML = "Starting next round in 5 seconds"; 

                             }
                                       ,6000);   // do it after time t    
                     
    
  });

Addendum: I want this block to be repeated a custom number of times, so I am using loop and merge on the block.


Leave a Reply