Running score variable with starting budget | XM Community
Question

Running score variable with starting budget

  • 16 November 2020
  • 1 reply
  • 5 views

Hallo together,
I am currently working on a survey on sports betting. Participants will be given a starting budget of $500. For each game they have the binare choice of betting $100 or passing. Depending on their answer and the true state of events will either win $200, lose $100 or keep their previous budget, if they decide to pass for a game.
I want to run an Embedded Data variable in the background, that keeps track of their balance but can be displayed after every single game as feedback to the participants. This is my current survey flow:
Screen Shot 2020-11-16 at 10.14.00.png
In the Feedback1 Block I can display the Budget data without a problem. However, I seem not to be able to add an Embedded Data Field to the score in the Feedback2 Block in order to update the Budget data field.
From previous blog posts I am assuming I may have to use Java, but I have never dealt with it before and do not know how to add it to a question of the flow. I have found the Java script option for each question and I can roughly read code.
One of the previous blog posts mentioned the following code which I adapted to my needs as far as I could. However, the jQuery part is all Greek to me:
Qualtrics.SurveyEngine.addOnload(function() {
  startScore = parseInt("${gr://SC_9Hx0GFbjdRKLAAB/Score}");
  choiceScores = {"Bet $100" : 200, "Pass" : 0};
  jQuery("#"+this.questionId+" input[type=radio]").click(function() {
    var score = startScore + choiceScores[jQuery(this).attr("choiceid")];
    jQuery("#totalScore").html(score);
  });
});

I am thankful for any tips and tricks!


1 reply

Userlevel 7
Badge +27

Hi there, if you still need, this can be put in place without JavaScript by updating an Embedded Data field with Math Operations after each game. First, over in Scoring, create a Scoring Category for each game. Then, try setting the Survey Flow up like the below:
GameBudget.png

Leave a Reply