Hi guys, I need to conduct a psychology experiment asking participants to type in their thought within certain time limits. Whenever they press the blue button, a new text block will appear and hide the previous one. This will last for 12 mins. This is the Javascript I use:
Qualtrics.SurveyEngine.addOnload(function()
{
let loopNumber = Number("${lm://CurrentLoopNumber}")
if (loopNumber > 1) {
let timeLimit = "${e://Field/time_limit}"
let startTime ="${e://Field/start_time}"
let currentTime = new Date().getTime()
console.log("Loop: " + loopNumber)
console.log("Start Time: " + startTime)
console.log("Current Time: " + currentTime)
let timeElapsed = currentTime - startTime
console.log("Time elapsed: " + timeElapsed)
if(currentTime - startTime >= timeLimit) {
Qualtrics.SurveyEngine.setEmbeddedData("time_is_up", 1);
this.clickNextButton()
}
}
});
And this is what I set
However, the problem is after 12mins (now is 15s), unless you physically press the blue button to terminate the experiment (looping the remaining text box), it will stay on the text block page, so my participants can not realise the time is up. Could someone help me with the code, so the experiment will auto-forward after 12mins? I am really new to java.
Many thanks
Page 1 / 1
Use setInterval to keep track of time on the page.
https://community.qualtrics.com/XMcommunity/discussion/comment/47039#Comment_47039Hi TomG,
I am really new to Java, even the code I use is from a friend, could you explain more about this setInterval please?
Many thanks
setInterval executes a function every x milliseconds. So, you could have the function decrement the time remaining every second (1000 milliseconds) and click the Next button when it reaches zero.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.