Hi,
I made this code which generates 127 random pairs of numbers out of 190. My intention with this code is to get the first number of the pair in the first answer option of my multiple choice question and second in the second option. And this so for 127 questions. So that each participant has a different set of 127 pairs of numbers. But it's my first time using Qualtrics and I can't seem to find how I can make this code work in my question. I added it to the question I want it to work on (in the onload funtion), and that's about as far as I've gotten.
Your help would be greatly appreciated.
This is the code. It should be correct, but if you have any remarks, please share them with me.
Qualtrics.SurveyEngine.addOnload(function()
{
// Make age combo's without duplicates or same age comparisons.
var ageCouples = [];
for (i = 0; i < 77; i+=4) {
for (j = 0; j < 77; j+=4) {
if(i < j){
ageCouples.push([i, j]);
}
}
}
// function to randomise order of elements in array
function shuffle(array) {
var lastIndexNotShuffled = array.length -1;
var temporaryValue;
var randomIndex;
// While there remain elements to shuffle...
while (lastIndexNotShuffled !== 0) {
// random index between first and last element (both inlcuded)
randomIndex = Math.floor(Math.random() * lastIndexNotShuffled);
// And swap it with the current element.
temporaryValue = array[lastIndexNotShuffled];
array[lastIndexNotShuffled] = array[randomIndex];
array[randomIndex] = temporaryValue;
lastIndexNotShuffled -= 1;
}
return array;
}
shuffle(ageCouples);
// amount of trials to be done
var amountOfTrials = Math.ceil(ageCouples.length * 2/3);
for(i=0; i
// console.log("pair"+ i + "age" + 1 + " : " + ageCouples[i][0]);
// console.log("pair"+ i + "age" + 2 + " : " + ageCouples[i][1]);
// console.log("\\n");
// goes from pair1age1 -> pair127age1 and pair1age2 -> pair127age2
Qualtrics.SurveyEngine.setEmbeddedData("pair"+ i + "age" + 1, ageCouples[i][0]);
Qualtrics.SurveyEngine.setEmbeddedData("pair"+ i + "age" + 2, ageCouples[i][1]);
}
});
How do I make my JS code work in my Question?
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.

Now, there's a slight possibility that Qualtrics assigns both of them the same value, so I add this to the first question of the survey: