0

I have a survey in Qualtrics, and I need to do some calculations based on the answers from a matrix table. I need to find the "switchpoint."

The answers array will look something like this:

[0 0 0 1 1 1 1 1 1 1]

So for the above array, the switchpoint is between the 3rd and 4th element.

I'm not sure what the best way is to do this, and I've been struggling to figure it out - any guidance is most appreciated.

Here's what I'm trying to do:
I created an embedded data variable in survey flow to output the selected answers.

Var block1= [‘${q://QID664/SelectedAnswerRecode/1}’],
‘${q://QID664/SelectedAnswerRecode/2}’],
[‘${q://QID664/SelectedAnswerRecode/3}’],
[‘${q://QID664/SelectedAnswerRecode/4}’],
[‘${q://QID664/SelectedAnswerRecode/5}’],
[‘${q://QID664/SelectedAnswerRecode/6}’],
[‘${q://QID664/SelectedAnswerRecode/7}’],
[‘${q://QID664/SelectedAnswerRecode/8}’],
[‘${q://QID664/SelectedAnswerRecode/9}’],
[‘${q://QID664/SelectedAnswerRecode/10}’];

Then, parse

integers- var block1= parseInt([block1])

});

Then, i need to check the array in 2 ways to make sure it's "valid":

  • check to see if values in block1 array are all equal to 1 or all equal to 0
  • check to see if there are more than 2 switchpoints
  • if either of these are true, then this block is invalid

Then, find switchpoint and set that to a value.

1 Answer 1

1

A couple of things. First, your array definition is wrong...only one set of brackets and no 'smartquotes'. Second, parseInt only operates on a single string. It should be:

Var block1= [parseInt("${q://QID664/SelectedAnswerRecode/1}"),
parseInt("${q://QID664/SelectedAnswerRecode/2}"),
parseInt("${q://QID664/SelectedAnswerRecode/3}"),
parseInt("${q://QID664/SelectedAnswerRecode/4}"),
parseInt("${q://QID664/SelectedAnswerRecode/5}"),
parseInt("${q://QID664/SelectedAnswerRecode/6}"),
parseInt("${q://QID664/SelectedAnswerRecode/7}"),
parseInt("${q://QID664/SelectedAnswerRecode/8}"),
parseInt("${q://QID664/SelectedAnswerRecode/9}"),
parseInt("${q://QID664/SelectedAnswerRecode/10}")];

Now block1 is an array of integers. You can loop through it with a for statement:

for(i=0;i<block1.length;i++) {
  //Do something with block1[i]
}
Sign up to request clarification or add additional context in comments.

4 Comments

It is really difficult to read code in comments. I recommend you accept this answer, then create a new post with your additional questions.
I've been trying to run this in Qualtrics for half the day, and haven't really gotten anywhere. I'm not sure if it's the code or maybe i didn't set something up right in qualtrics. I guess the first basic question to ask is, does my javascript code go in the question after the question with responses?
Click the cog to the left of the question and select JavaScript. If you don't have a JavaScript option, contact your brand administrator.
Yeah, that's where i've been trying to run it. Any other ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.