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>