How to convert an array into string and save to an embedded variable. | XM Community
Skip to main content

Hello, 

I am designing a study wherein participants are asked to watch a video and press the spacebar every time the people in the video show “bad behaviour”.

I’ve found some code to do this:

let question = this;

/* hide next button */
question.hideNextButton();

/* when the video end, click on next button */
jQuery($('videoPlayer')).on("ended", function() { setTimeout(function () {jQuery('#NextButton').click();},1000); });


document.onkeydown = function(event) {
if (event.which == 32) {
let pressCurnetTime = $('videoPlayer').currentTime /* the time when the subject pressed space */
event.preventDefault();


}

My question is this: how do I make the time an array and record each time the spacebar is pressed?

Following this, how would I convert the array to a string variable and save it to an embedded data variable? 

 

Thank you for your help

The code you are using cold be a lot better, but to answer your question…

Initialize an array variable:

let myArray = =];

Add the times to the array:

myArray.push($('videoPlayer').currentTime);

Join the array into a comma separated string:

let string = myArray.join(",");

 


The code you are using cold be a lot better, but to answer your question…

Initialize an array variable:

let myArray = =];

Add the times to the array:

myArray.push($('videoPlayer').currentTime);

Join the array into a comma separated string:

let string = myArray.join(",");

 

Thank you so, so much for your help. I appreciate it. You've saved me a headache! Just additionally, how would I save the array of the times of each space bar press to an embedded data variable so that I can see them easily? Thanks again


Leave a Reply