not able to use Javascript successfully | XM Community
Skip to main content
I am trying to enable a rolling dice on my survey with the instruction from the link below.



https://tschiemer.github.io/qualtrics-gambling/dice/dice.html

https://github.com/tschiemer/qualtrics-gambling



However, I am not successful to realize it. I saved the dice javascrip file and dice image files into my dropbox and insert the code below to my qualtrics survey. I am not familiar with Javascript language. Can anyone help to figure out how can I fix the problem?



Thank you very much in advance.





<!-- include dice source.-->

<script src= "https://www.dropbox.com/sh/460ga74bw0mdw02/AAC2ngEyoH41YjGjgwTBU5ada?dl=0/dice.js" type="text/javascript"> </script>



<!-- Actual dice html here -->

<div id="dice"></div>

<br>

<button id="throw">Throw dice!</button>



new Dice('dice','throw',{

value_set: [

{key: '1',probability: 1},

{key: '2',probability: 1},

{key: '3',probability: 1},

{key: '4',probability: 1},

{key: '5',probability: 1},

{key: '6',probability: 1}

],

images : {

base_url: “https://www.dropbox.com/sh/460ga74bw0mdw02/AAC2ngEyoH41YjGjgwTBU5ada?dl=0/image/“,

ext: '.png',

init: 'qmark1.png'

},

result_callback: function(throw_nr,result_key){



// Save result to embedded data field (need

//not be set through survey flow settings)

Qualtrics.SurveyEngine.setEmbeddedData('result_matrix_embedded'+throw_nr, result_key);



}

});
Hello @kk321 ,



I have added the dice code in qualtrics javascript section and html code in question text.

Here is the preview link
> @PraDeepKotian_Ugam said:

> Hello @kk321 ,

>

> I have added the dice code in qualtrics javascript section and html code in question text.

> Here is the preview link

>

>



Hi,

Thank you so much for your help!

I tried to add the code to the qualtrics javascript section in two different ways but it keeps saying error with both methods. Do you know how to fix the issue? Thank you very much.



Method 1:

> <!-- include dice source.-->

> <script src= > "https://www.dropbox.com/sh/460ga74bw0mdw02/AAC2ngEyoH41YjGjgwTBU5ada?dl=0/dice.js" type="text/javascript"> </script>

>

> new Dice ('dice','throw', {

> value_set: [

> {key: '1',probability: 1},

> {key: '2',probability: 1},

> {key: '3',probability: 1},

> {key: '4',probability: 1},

> {key: '5',probability: 1},

> {key: '6',probability: 1}

> ],

> images : {

> base_url: “https://www.dropbox.com/sh/460ga74bw0mdw02/AAC2ngEyoH41YjGjgwTBU5ada?dl=0/image/“,

> ext: '.png',

> init: 'qmark1.png'

> },

> result_callback: function(throw_nr,result_key){

>

> // Save result to embedded data field (need

> //not be set through survey flow settings)

> Qualtrics.SurveyEngine.setEmbeddedData('result_matrix_embedded'+throw_nr, result_key);

>

> }

> });

>

>

> error: Invalid JavaScript! You cannot save until you fix all errors: Unexpected token <

>



Method 2:

>

> I added all code from the dice.js before the integration code. The code is too long and I can't paste it here.

>

> new Dice ('dice','throw', {

> value_set: e

> {key: '1',probability: 1},

> {key: '2',probability: 1},

> {key: '3',probability: 1},

> {key: '4',probability: 1},

> {key: '5',probability: 1},

> {key: '6',probability: 1}

> ],

> images : {

> base_url: “https://www.dropbox.com/sh/460ga74bw0mdw02/AAC2ngEyoH41YjGjgwTBU5ada?dl=0/image/“,

> ext: '.png',

> init: 'qmark1.png'

> },

> result_callback: function(throw_nr,result_key){

>

> // Save result to embedded data field (need

> //not be set through survey flow settings)

> Qualtrics.SurveyEngine.setEmbeddedData('result_matrix_embedded'+throw_nr, result_key);

>

> }

> });



error: Invalid JavaScript! You cannot save until you fix all errors: Unexpected token ILLEGAL

Leave a Reply