Hello! I am trying to create a study in which participants will be randomly shown 5 prewritten lists of items out of ~400 lists, and will be asked to rate each item in each list on a 7-point scale. Currently my code to display the lists looks like this:
Qualtrics.SurveyEngine.addOnload(function() {
// define an array of 400ish lists (5 shown as an example)
const allCS = S"ex1", "ex2", "ex3", "ex4", "ex5"];
// function to randomly select 5 lists from the array
function selectRandomChoiceSets(array, count) {
const shuffled = array.sort(() => 0.5 - Math.random());
return shuffled.slice(0, count);
}
// randomly select 5 lists
const selectedCS = selectRandomChoiceSets(allCS, 5);
// display the lists within the question named ‘cs’
const questionContainer = document.getElementById('cs');
selectedCS.forEach(function(choiceSet, index) {
const choiceSetElement = document.createElement('div');
choiceSetElement.innerHTML = '<h3>Choice Set ' + (index + 1) + '</h3><ul><li>' + choiceSet + '</li></ul>';
questionContainer.appendChild(choiceSetElement);
});
});
I think I did something wrong with the display logic. Does anyone know how to get the lists to display?
Thank you!