Creating a quiz-style question | XM Community
Question

Creating a quiz-style question

  • 24 April 2020
  • 2 replies
  • 14 views

Userlevel 2
Badge +6

I have a survey that will be passing a store ID via query strings. There is a fixed list of store IDs containing around 100 entries. I set up 2 embedded data that will take this store ID as a recode value to determine store name and address.
For example:
store id can be from 1 to 100
storename (embedded data):
1 is Store A
2 is Store B
etc.

storeaddr (embedded data):
1 is Store A (5th and York)
2 is Store B (Madison and Pape)
etc.

Now, I need to set up a question that will contain 5 answer options one of which is the store passed via query strings. The remaining four answer options will be randomly selected from the list of 100 stores.

Which store did you visit last weekend?
Store D
Store G
Store X
Store P
Store Y

If Store X is the store that was passed via parameter string was not selected, we terminate the survey.

Is this possible? This is a survey that we are migrating from Confirmit.



2 replies

Userlevel 3
Badge +2

Yes, I think this can be done using JavaScript.
Let's work the question backward.
Step 1:
I will first create the question, let's call it Q3, "Which store did you visit last weekend", and set the choices with value pull from embedded data using "Insert piped text" function.
For instance:
${e://Field/randomStoreA}
${e://Field/randomStoreB}
${e://Field/randomStoreC}
${e://Field/randomStoreD}
${e://Field/randomStoreE}
Step 2:
Then I will add a question Q2 before Q3 and add a page break between them, and in Q2, which is a Descriptive Text question, I will add JavaScript to it.
In the JavaScript, I will access the "store ID" passed in from the query param using embedded data. Then I will use random number to randomly pick the other 4 stores that's different than the "store ID". Once I got all 5 store IDs, I will look up its name and randomly store the name in the randomStoreA, randomStoreB, randomStoreC, randomStoreD, randomStoreE embedded data. And I will also store the correct answer in another embedded data called correctStoreName.
Step 3:
Add a branching step survey flow after Q3. And compare the answer of Q3 against the correctStoreName embedded data and branch to end or survey or the next question.

Userlevel 2
Badge +6

Do you have the JavaScript code to make this happen?

Leave a Reply