I'm trying to make a lottery where the probability of winning is dependent on how a participant does during the survey. As a result I want to make a random number where the upper limit is based on a variable within the survey. I saw the below previous discussion that suggested "nesting" embedded data was not possible.
https://community.qualtrics.com/XMcommunity/discussion/6968/displaying-a-random-number-within-question-and-choice-options-using-javascriptThis would suggest I can't make a random number where the upper limit is based on how well the participant did. I had been planning to use the below coding.
RandomNumber = ${rand://int/ 1 : e://Field/VariableName}
If RandomNumber < Variable2 then
Win the Lottery
If RandomNumber ≥ Variable2 then
Lose the Lottery.
Can anyone help me to figure out how to code this. The only way I can think of would be to manually make a lot of if Random number = 1, If random number = 2 etc to manually code it but I thought there might be a faster way. Any help is appreciated.
Thank You
Making the limit of the random number depend on the values earned.
Best answer by ahmedA
You'll need to use JS for this.
- Create an ED (let's call it
UpperBound
) and store the value of the upper limit in it. - Then, in any question before the random number is required and after the UpperBound value has been stored, add the following JS:
Qualtrics.SurveyEngine.addOnReady(function () {
let random_number = Math.random() * Number("${e://Field/UpperBound}");
Qualtrics.SurveyEngine.setEmbeddedData("RandomNumber", random_number);
});
You can then use this
RandomNumberED, just like any other.
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
