Skip to content

Skipping questions

Nick Ruggieri edited this page Oct 21, 2020 · 11 revisions

Simple skip

Sometimes based on the response of a question, you may want to skip several questions.

[Q1!] Do you like chocolate?
(1) yes
(0) no -> Q2

[Q1A] Which type of chocolate do you prefer?
(0) dark chocolate
(1) milk chocolate
(2) white chocolate

[Q2] Do you wear socks at work?
(1) yes
(0) no

In this set of questions, the user is first presented with the Do you like chocolate question. If the user selects no, they are send to question Q2, Do you wear socks at work?. Had the user selected yes, they would have gone on to question Q1A. The exclamation point after the question id [Q1!] means the user must select an answer. But what if we want to allow the user not to respond. The previous set of question would first display Q1, then display Q1A if no response is given. If you want to skip to question Q2 with no response add the special #NR label to mark this.

[Q1!] Do you like chocolate?
(1) yes
(0) no -> Q2
< #NR -> Q2 >

[Q1A] Which type of chocolate do you prefer?
(0) dark chocolate
(1) milk chocolate
(2) white chocolate

[Q2] Do you wear socks at work?
(1) yes
(0) no

Multiple choice skipping

Sometimes the you may have a multiple choice question where the user can choose multiple options, and each response has a set of follow-up questions. If you tried you question like this,

[Q1] Select from the following list any activity you performed at work yesterday
[1] wrote -> Q1A
[2] read -> Q1B
[3] played a game (including sports) -> Q1C
[4] went to a meeting -> Q1D
< #NR -> Q2>

[Q1A] How many pages did you write? |__|__|

[Q1B] How many pages did you read? |__|__| 

[Q1C] What game did you play |__|

[Q1D] How did that work our for you? |__|

[Q2] Do you have any children
(1) yes
(0) no

you would notice what appears to be strange results. Let's say you choose "wrote" and "played a game". The order of the questions would be: [Q1] -> [Q1A] -> [Q1C] -> [Q1D] -> [Q2]. This might seem weird, but it makes sense when you think about how the questions should be ordered. First, from [Q1] both [Q1A] and [Q1C] need to be asked. So, in those are dropped in a queue. After answering [Q1A], [Q1C] is in the next question queue. So, it is displayed. After [Q1C], the queue is empty. The next question is Q1D, so you see that question next. To handle this case we use the following syntax:

[Q1!] Do you like chocolate?
(1) yes
(0) no -> Q2
< -> Q2 >

[Q1A] Which type of chocolate do you prefer?
(0) dark chocolate
(1) milk chocolate
(2) white chocolate

[Q2] Do you wear socks at work?
(1) yes
(0) no

In order to handle this case appropriately, you need to use the always add element < -> QID >, which always adds the question with id QID to the queue as in this example:

[Q1] Select from the following list any activity you performed at work yesterday
[1] wrote -> Q1A
[2] read -> Q1B
[3] played a game (including sports) -> Q1C
[4] went to a meeting -> Q1D
< -> Q2>

[Q1A] How many pages did you write? |__|__|

[Q1B] How many pages did you read? |__|__| 

[Q1C] What game did you play |__|

[Q1D] How did that work our for you? |__|

[Q2] Do you have any children
(1) yes
(0) no

Now, when the user chooses "wrote" and "played a game" for [Q1], the queue is filled with [Q1A],[Q1C], and [Q2]. The order is [Q1] -> [Q1A] -> [Q1C] -> [Q2]. This does continue to become more complicated for cases where you have multiple follow up questions. In this case, your question MUST contain skip logic to continue, as an example:

[Q1] Select from the following list any activity you performed at work yesterday
[1] wrote -> Q1A
[2] read -> Q1B
[3] played a game (including sports) -> Q1C
[4] went to a meeting -> Q1D
< -> Q2>

[Q1A] How many pages did you write? |__|__|
< -> Q1E >

[Q1E] What writing utensils did you use
[0] pencil
[1] pen
[2] typewriter (whatever that is)
[3] computer

[Q1B] How many pages did you read? |__|__| 

[Q1C] What game did you play |__|

[Q1D] How did that work our for you? |__|

[Q2] Do you have any children
(1) yes
(0) no

This more complicated case is easily viewed as a tree. Starting with [Q1] as the parent node, all the selected responses are add as children to [Q1]. The < -> > (always add) element adds a child to parent node as well. In this case, a no response (#NR) is not needed because it is handled by the always add element. The tree for the case when "wrote" and "played can be viewed as

The quest app models a questionnaire as a tree. When the skip logic doesn't specify the next question, the default is to go to the following question in the markdown. Whereas you can always specify the skip logic, only using skip logic when necessary is probably best practice.

Conditional If

Sometimes there is a certain condition that needs to be met in order to go to the next question. Using the if= syntax, the user is able to skip to a question based on when a previous condition is met. The user is also able to skip to another question if that condition is not met.

[Q1] Do you like blue?
(1) Yes
(2) No

[Q2] Do you like red?
(1) Yes
(2) No
< |if=and(equals(Q1,1),equals(Q2,1))| -> Q4 >

[Q3] Do you like yellow?
(1) Yes
(2) No
< -> Q5 >

[Q4] You might like purple since you like Blue and Red!

[Q5,end] Thank you for taking the survey!

In this example, if the user chose Yes (1) for the first two questions, they would skip to question [Q4]. Else, the user would go from questions [Q1] -> [Q2] -> [Q3] -> [Q5].

Show Question If...

Another way to "skip" a question is using the displayif argument. This allows up to skip questions based on the value of previous response. Consider a long questionnaire a question near the end depends on a question at the beginning. Our arrow based skip logic fails. We chose to use a displayif to handle this case. As in this example.

[Q1] how many dogs do you own? |__|__| 

[Q2, displayif="greaterThanOrEqual(Q1,3)"] Why do you have so many dogs 
|__| 

[Q3] What is your name |__| 

In this example, if the user entered 3 or greater for question [Q1], question [Q2] would be skipped.

Known Functions

This displayif has many known functions. They include:

  • and
  • or
  • equals
  • lessThan
  • lessThanOrEqual
  • greaterThan
  • greaterThanOrEqual
  • difference
  • percentDiff
  • isDefined
  • isNotDefined
  • numberOfChoicesSelected