Hi There,
I'm have a list of images embedded in javascript, which I randomize without replacement 4 times (same image cannot appear twice) and then save to qualtrics as embedded text. Here is my current javascript:
Qualtrics.SurveyEngine.addOnload(function(){
function shuffle(array){
var counter = array.length,
temp, index;
while (counter > 0){
index = Math.floor(Math.random() * counter);
counter = counter-1;
temp = array[counter];
array[counter] = array[index];
array[index] = temp;
}
return array;
}
var BF1 = {'BF1' : "https://uwmadison.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_6MqvF92gFjIQdvL"};
var BA1 = {'BA1' : "https://uwmadison.co1.qualtrics.com/CP/Graphic.php?IM=IM_2ai3h65t8KDXKAt"};
var BF2 = {'BF2' : "https://uwmadison.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_3lOsHtTOhx9brSd"};
var BA2 = {'BA2': "https://uwmadison.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_6rmHa8ZemfjNYI5"};
var BF3 = {'BF3': "https://uwmadison.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_0IWXF8YYUj7mLbv"};
var BA3 = {'BA3': "https://uwmadison.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_eV4UXXA1KeTmmTX"};
var BA4 = {'BA4': "https://uwmadison.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_1Odotlg2jvIMciV"};
var BF4 = {'BF4': "https://uwmadison.co1.qualtrics.com/ControlPanel/Graphic.php?IM=IM_9zgpuMgqHh7QQ2F"};
var myArray=[BF1,BA1,BF2, BA2, BF3,BA3, BA4, BF4];
shuffle(myArray);
Qualtrics.SurveyEngine.setEmbeddedData("firstImage",Object.values(myArray[0])[0]);
Qualtrics.SurveyEngine.setEmbeddedData("firstImageName",Object.keys(myArray[0])[0]);
Qualtrics.SurveyEngine.setEmbeddedData("secondImage",Object.values(myArray[1])[0]);
Qualtrics.SurveyEngine.setEmbeddedData("secondImageName",Object.keys(myArray[1])[0]);
Qualtrics.SurveyEngine.setEmbeddedData("thirdImage",Object.values(myArray[2])[0]);
Qualtrics.SurveyEngine.setEmbeddedData("thirdImageName",Object.keys(myArray[2])[0]);
});
I want to add a condition, which suggests that an image name that has the same number cannot be drawn in the next draw.
To demonstrate, my array includes the following vars: BF1, BA1, BF2, BA2, BF3, BA3, BF4, BA4. And I want to draw 3 images with the said condition. Let's say in the first draw I drew BA2. So the possible vars in my next draw will be:
BF1, BA1, BF3, BA3, BF4, BA4 (note that I removed any var with the number 2).
Let's say my next drawn var was BA1, now the possible list of vars is:
BF3, BA3, BF4, BA4 (note that I removed any var with the numbers 2 or 1).
I hope this makes sense, and I'd appreciate any help!
Randomize images without replacement, with conditions
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.
