display one randomly selected question and the respondent's choice of that question | Experience Community
Skip to main content
Question

display one randomly selected question and the respondent's choice of that question

  • Mar 10, 2020 1:42 AM UTC
  • 3 replies
  • 55 views

Forum|alt.badge.img
I want to display to the respondent one of the randomly selected questions of the whole survey (100 questions), and his/her choice of that question. What I did but failed, is that I set a question ID to be embedded data randQID = ${rand://int/1:100}, and I replace question ID in the piped text with my randQID in order to display that randomly selected question's choice description and its selected choice. One randomly selected question is ${q://QIDrandQID/ChoiceDescription/1} or ${q://QIDrandQID/ChoiceDescription/2}, and your choice is ${q://QIDrandQID/ChoiceGroup/SelectedChoices} What should I do to make it possible?

3 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • Mar 10, 2020 10:43 AM UTC

We cannot dynamically call the qid from client side.

Hence create a key value pair array in JS where in key will be the piped in question text and value will be its respective piped in selected choice. Randomize this array and select any key value pair to display.


Forum|alt.badge.img
  • Author
  • Mar 10, 2020 2:51 PM UTC
@rondev Are you saying create an object JS like the following? I selected one random number. How do I display the key and value to a question in the survey of the type a descriptive text? var object = {}; object[‘${q://QID1/ChoiceDescription/2}'] = ${q://QID1/ChoiceGroup/SelectedChoices}; object[‘${q://QID2/ChoiceDescription/2}'] = ${q://QID2/ChoiceGroup/SelectedChoices}; … object[‘${q://QID100/ChoiceDescription/2}'] = ${q://QID100/ChoiceGroup/SelectedChoices}; randomN = Math.floor(Math.random() * object.length);

Forum|alt.badge.img
  • Author
  • Mar 10, 2020 3:38 PM UTC
@rondev I figured it out. Thanks!