 # Problems with text input from first trial in PsychoJS

URL of experiment: https://gitlab.pavlovia.org/evamaria/learningphase

Description of the problem:
Hi all,

i´m creating a working memory experiment in which participants have to learn two lists of four digits. The lists with the digits are created at the beginning of the experiment with the following code component:

``````function shuffle(a) {
var j, x, i;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = a[i];
a[i] = a[j];
a[j] = x;
}
return a;
}

digits = [1, 2, 3, 4, 5, 6, 7, 8, 9];
shuffle(digits);

d1 = digits;
d2 = digits;
d3 = digits;
d4 = digits;
d5 = digits;
d6 = digits;
d7 = digits;
d8 = digits;
console.log(d1, d2, d3, d4, d5, d6, d7, d8);

digit1 = d1.toString();
digit2 = d2.toString();
digit3 = d3.toString();
digit4 = d4.toString();
digit5 = d5.toString();
digit6 = d6.toString();
digit7 = d7.toString();
digit8 = d8.toString();
``````

In a learning phase, participants have to type in the eight digits (eight trials of the Routine “LearningPhase”) and if they manage to do that correctly three times in a row, the next phase of the experiment starts. In the excel file the correct answer (corrAns) is defined as digit1, digit2, digit3 and so on and I refer to this with “eval(corrAns)”, see the following code component, which is at the End of the routine “LearningPhase”:

``````if (type_digit.text === eval(corrAns)) {
acc.push(1);
}
else if (type_digit.text != eval(corrAns)) {
acc.push((- 1));
}
``````

So in every trial, the text input (type_digit.text) is compared to the correct digit. A correct trial is saved as “1” in the acc array and an incorrect trial as “-1”. For the digits 2-8 this works perfectly fine, but for some reason it´s not working for the first digit. Although I´m typing in the correct digit and in the console log it is the same as digit1 (and both are strings) it´s always coded as incorrect. I inserted a “digit0” before digit1, and again, the first trial was coded as incorrect (digit0). So there is not a problem with digit1 but rather with the text input in the first trial…but I´m really stuck at this point…so any help is highly appreciated Thanks in advance!

1 Like

Do you get this behaviour only when you run your experiment online with PsychoJS, or do you get the same behaviour with PsychoPy offline?

How did you check that? Do you log the value of the your evaluation?

Hi Lukas,
good point, sorry (!!) I forgot to mention that the problem only occurs online, everything works fine offline. I can see in the console that it´s coded as “-1” in the acc array. Also, the Feedback which is shown afterwards is always as if it was incorrect (for correct trials “ok” is shown, for incorrect trials, the correct digit is shown)