Hi @w29913 ,
I am not very knowledgeable on JavaScript. I used the piped text of the form field question instead.
Then, i realised that they are concatenating when I tried to add them.
Hence, I changed the data type of value1 and random1, which are likely string type, to numbers before adding them.
Qualtrics.SurveyEngine.addOnload(function()
{
const random1options=[0,2,4,6];
const random2options=[0,20,30,40];
let random1=random1options[Math.floor(Math.random() * random1options.length)];
let random2=random2options[Math.floor(Math.random() * random2options.length)];
while (random1 === 0 && random2 ===0) {
random1=random1options[Math.floor(Math.random() * random1options.length)];
random2=random2options[Math.floor(Math.random() * random2options.length)];
}
console.log("Random1: " +random1);
let value1= "${q://QID20/ChoiceTextEntryValue/2}";
let sum= Number(value1)+ Number(random1);
console.log("value1: " +value1);
console.log("sum: " +sum);
this.getQuestionTextContainer().innerHTML="xx increase by " + sum +" and xx increase by "+random2 +"%, which of the following you will choose?";
});