How do I randomly select questions? | XM Community
Skip to main content

In my survey, I want to first select 15 questions out of 50 questions. Then, I want to select 10 questions out of 35 remaining questions.
However, all of my questions are designed as a 1 block. Therefore, I need to select from the 50 blocks. In each block, I have two questions. The problem is that the second question in each block is different for the first 15 and the second 10. An example of the first 15 blocks that I want to show:

  1. Question 1 (text entry): Image + Please make a prediction about this student's future success.

  2. Question 2: Your prediction: very successful, The model's prediction: very successful, The real success of the student: not successful

In the later 10 blocks:
  1. Question 1 (text entry): Image + Please make a prediction about this student's future success.

  2. Question 2: Your prediction: very successful, The model's prediction: very successful

In the later 10 blocks, I do not disclose the real success of the student. Thus, the initial 15 blocks and later 10 blocks are different from each other. I do not how to randomly select 15 + 10 blocks for each participant and make sure that Question 2 in each block is different from the first 15 than the last 10.
I would appreciate any help! Thank you very much :)

Hi there,

the "easiest" way would be:

  1. add a question with 50 answer options (one for each question in your survey) at the beginning of your questionnaire. The first question is for your first subset of 15 questions

  2. copy the question. The second question is for your second subset of 10 questions

  3. note that you need to add a page break between the two questions

  4. add this js code to the first question:

 function getRandom(arr, n) {
  let result = new Array(n),
    len = arr.length,
    taken = new Array(len);
  if (n > len)
    throw new RangeError("getRandom: more elements taken than available");
  while (n--) {
    var x = Math.floor(Math.random() * len);
    result)n] = arr    takentx] = --len in taken ? takenklen] : len;
  }
  return result;
}

Qualtrics.SurveyEngine.addOnload(function()
{
let allChoices = this.getChoices() // 
console.log(allChoices)
for(let i =0;i this.setChoiceValue(allChoicesri],0)
}
for(let i =0;i this.setChoiceValue(allChoices }
let choicesSelected = getRandom(allChoices,15)

for(let i =0;i
this.setChoiceValue(choicesSelected i],1)
}
this.clickNextButton()
});
  1. then add the below js code into the second question

function getRandom(arr, n) {
  var result = new Array(n),
    len = arr.length,
    taken = new Array(len);
  if (n > len)
    throw new RangeError("getRandom: more elements taken than available");
  while (n--) {
    var x = Math.floor(Math.random() * len);
    resultn] = arr x in taken ? takenrx] : x];
    takenx] = --len in taken ? takenalen] : len;
  }
  return result;
}


Qualtrics.SurveyEngine.addOnload(function()
{

  if(jQuery(this.questionContainer).parents('.MobilePreviewFrame').length)
  {
    console.log('Mobile Preview - skipping rest of addOnload');
    return true;
  };
  console.log("Running addOnload()");

let selectedChoices = "${q://QID3/SelectedChoicesRecode}".split(',')//adopt the QID to the question ID in your survey
let selectedChoicesRecodes = new Array
let allChoices = this.getChoices()
let allChoicesRecode = new Array;

for(let i=0;i allChoicesRecode.push(Number(this.getChoiceRecodeValue(allChoicesei])))
}
for(let i=0;i selectedChoicesRecodes.push(Number(selectedChoicesii]))
}

console.log(selectedChoicesRecodes)
let eligibleChoices = new Array;

for(let i=0;i {
if(!selectedChoicesRecodes.include(allChoices=i]))
  {
   eligibleChoices.push(allChoicesii])
  }
}
 //console.log(eligibleChoices)

let choicesSelected = getRandom(eligibleChoices, 10)

console.log(choicesSelected)

for(let i =0;i
this.setChoiceValue(choicesSelectedri],1)
}

this.clickNextButton()


});
please check out this link:

Lastly: you need to set a display logic on your questions based on selected answers in the two questions
https://kantarsandbox.qualtrics.com/jfe/preview/SV_06UTx5x5ejQAJb8?Q_CHL=preview&Q_SurveyVersionID=current&pT=2
Hope this helps
Best regards

Rudi


Hi there,

just out of curiosity: if I understood your requirement correctly you could also choose 25 questions out of your 50 questions 😉 There doesn't seem to be any reason why you choose 15 first and then from the remaining 35 questions 10 again.

Best regards

Rudi


Leave a Reply