Math operation with Embedded data | XM Community
Solved

Math operation with Embedded data

  • 2 August 2019
  • 5 replies
  • 171 views

Hi! I created a JavaScript to show a random value at the respondent and then stored that value (e.g. 0.5). I used the following java-script:

Qualtrics.SurveyEngine.addOnReady(function() {
var words = [0.50, 1.50, 3, 5]; //Your words
var i = Math.floor(Math.random() * words.length); //randomly select an index
var my_word = words[i]; //select a word
Qualtrics.SurveyEngine.setEmbeddedData( 'word', my_word); //Send the word to the Qualtrics output, otherwise you would not know which participant get which word
document.getElementById("random").innerHTML = my_word; //show the word to respondents
});

Now I would do a maths operation with the stored value (e.g. 0.5) plus a fix value (e.g. 3) and show it in a question. For example, I would have the following question:
If you said yes to the question above, (where showed 0.5 - ${e://Field/word} )
are willing to pay £ 0.5 + 3? (I want to show that maths operation automatically)


How can I do this? With Javascript or Piped Text?
icon

Best answer by valedigen 2 August 2019, 16:01

View original

5 replies

I found it using Piped text! It was a syntax issue: $e{ e://Field/word + 3 }
Now it works!
Userlevel 6
Badge +6
I personally wouldn't use any JavaScript here at all.

This could all be done by the Survey Flow and will be more visible to later editors of the survey.

See here: https://qualtricssfi.az1.qualtrics.com/jfe/preview/SV_cA6fMansyhMdJ0F?Q_SurveyVersionID=current&Q_CHL=preview

Survey Flow: !

Importable Survey Example attached
Userlevel 4
Badge +17
I agree shouldn't need JS at all.

!
Thanks very much @mattyb513! I'll change, this solution looks easier. In this case have the values the same probability of being randomly extracted? I noted that using the JS random fuction this did not happen.
Userlevel 6
Badge +6
There is an option to "Evenly Present" elements. If you do that it basically keeps them all equal so there is not an equal probability, but the system keeps your overall results equal.

If you do not check that box it just chooses at random. There is an equal probability each time that any of the options will be chosen. This may or may not lead to equal results, due to the way probabilities work.

Leave a Reply