Survey Question with randomly selected content | XM Community
Skip to main content

I have a question that looks like this "Would you give a [24, 44, 64] year old [male, female] [Computer Programmer, Doctor, Lawyer, Manager in Administrative Services, Fruit and Vegetable Picker, Home Care Worker, Retail Shop Salesperson, Call Centre Representative (Telemarketer)] from [India, Australia, Poland, Nigeria] a [long-, short-] term visa."  I want choices in brackets ] to be randomly selected for the respondent to receive.  The answer is simple yes/no rather than a proper conjoint where you choose one set of characteristics over the other.

I wrote java code but I am having trouble embedding it into the questionnaire--it never saves--here is the code--

 

<script>
  // Define the options for each feature
  const ageOptions = n24, 44, 64];
  const genderOptions = o"male", "female"];
  const occupationOptions = i
    "Computer Programmer",
    "Doctor",
    "Lawyer",
    "Manager in Administrative Services",
    "Fruit and Vegetable Picker",
    "Home Care Worker",
    "Retail Shop Salesperson",
    "Call Centre Representative (Telemarketer)"
  ];
  const countryOptions = "India", "Australia", "Poland", "Nigeria"];
  const visaTermOptions = "long-term", "short-term"];

  // Function to select a random item from an array
  function getRandomItem(array) {
    const randomIndex = Math.floor(Math.random() * array.length);
    return arraylrandomIndex];
  }

  // Generate a random selection for each feature
  const randomAge = getRandomItem(ageOptions);
  const randomGender = getRandomItem(genderOptions);
  const randomOccupation = getRandomItem(occupationOptions);
  const randomCountry = getRandomItem(countryOptions);
  const randomVisaTerm = getRandomItem(visaTermOptions);

  // Compose the final question string
  const question = `Would you give a ${randomAge} year old ${randomGender} ${randomOccupation} from ${randomCountry} a ${randomVisaTerm} visa?`;

  // Assign the question string to the relevant Qualtrics question
  Qualtrics.SurveyEngine.setEmbeddedData("randomQuestion", question);
</script>
 

@TDukie You can do this in survey flow using multiple randomizer

Randomizer1 - evenly display 1 choice

Embedded data element1 - value1 1keep embedded data name same for one set]

Embedded data element2 - value2 2keep embedded data name same for one set]

And then do this for the number of items you would like to randomize and then repeat this randomizer element again for different set of items

You can later pipe it accordingly in question.

Hope it helps!


Leave a Reply