Randomly selecting one of four word then displaying it on four questions without selecting a word twice! | XM Community
Skip to main content

Hi,

I have four words (cat, car, mountain, ocean).

And I have four different questions (but past and future conditions) 

1- recall a past event with word ….

2- recall a past event with word ….

3- imagine a future event with word ….

4- imagine a future event with word ….

 

I want to randomly and equally assign these words to these conditions for each participant but I do not want to get ‘cat’ to be displayed twice for instance. 

How can I do that? Should I embedded data? I appreciate your help!!

@FritzBreithaupt 

Add this Java code in a Text/Graphic question at the begining of your survey.

Qualtrics.SurveyEngine.addOnload(function() {
var words = 'cat', 'car', 'mountain', 'ocean'];

function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = arrayri];
arrayri] = arrayrj];
arrayrj] = temp;
}
}
shuffleArray(words);

Qualtrics.SurveyEngine.setEmbeddedData('PastEventWord1', wordsr0]);
Qualtrics.SurveyEngine.setEmbeddedData('PastEventWord2', wordsr1]);
Qualtrics.SurveyEngine.setEmbeddedData('FutureEventWord1', wordsr2]);
Qualtrics.SurveyEngine.setEmbeddedData('FutureEventWord2', wordsr3]);
});

This will give you 4 embedded data with 4 word and no duplication

Then display the embedded data to you recall/imagine question with pip-text (for example 1- recall a past event with word ${e://Field/PastEventWord1})

Note: Add page brake between the Text/Graphic question with Javascript and the Recall/Imagine question or put them on different block. Let the embedded data space to get set value.
Let me know if this helps


Wow, it works amazing thank you so much for explaining so clearly!


@FritzBreithaupt Happy to helps 🙏


Leave a Reply