Dear Community,
In my survey, I want to present a series of sentences. I'd like these sentences to be constructed by words that are randomized from predetermined lists.
Example of a sentence: [Randy] is a [male] [doctor] experiencing [moderate] [sadness] [often], [moderate] [irritability] [almost always], and [severe] [lack of interest] [almost always].
The parts in the brackets are words that would be randomized from predetermined word lists.
To clarify, the name/word "Randy" would be randomly pulled from a list of names while the word "doctor" would be randomly pulled from a DIFFERENT list of jobs. The same goes for the other words.
Is there any way to do it? I would really appreciate your help!
How to randomize words to construct a sentence?
Best answer by ahmedA
You'll need to use JavaScript and edit question HTML for this. The following JS demonstrates it for two items being randomly selected. You can make the relevant changes:
Qualtrics.SurveyEngine.addOnReady(function () {
// This is for two fields, you can add as my fields as you require using the same format
// Just make sure you give different variable names
nms = "${e://Field/Names}";
nms = nms.split(",");
r1 = Math.floor(Math.random() * nms.length);
frts = "${e://Field/Fruits}";
frts = frts.split(",");
r2 = Math.floor(Math.random() * frts.length);
// Build the sentence to be used. Everything "inside quotes" is static
sentence = nms[r1].trim() + " is eating " + frts[r2].trim();
// Insert this sentence into the question
document.querySelector("#mysentence").innerText = sentence;
});
See here for the demo and the question HTML used. Each time you click restart survey, the text should be different. Since the options are few, you'll see repetitions.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
