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[0];
d2 = digits[1];
d3 = digits[2];
d4 = digits[3];
d5 = digits[4];
d6 = digits[5];
d7 = digits[6];
d8 = digits[7];
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!