Correct answer not registered in online experiment

Hi @MCutter,

The problem has to do with the following statement in the ‘code’ component of your ‘trial’ routine:

if ((DSAns.keys === corrAns)) {
    DSAns.corr = 1;
} else {
    DSAns.corr = 0;
}

The ‘DSAns.keys’ variable is an array, while the ‘corrAns’ variable is a string, so they are not technically equal.

Sometimes, using the ‘==’ operator instead of the ‘===’ operator can help in situations like this, because the ‘==’ operator is less picky, but unfortunately not in your case.

The solution has two parts. The first is to convert the ‘DSAns.keys’ variable to a string:

if ((DSAns.keys.toString() === corrAns)) {
    DSAns.corr = 1;
} else {
    DSAns.corr = 0;
}

The second part is to list the ‘corrAns’ variable in your Excel conditions file as 3,2,3 instead of [“3”,“2”,“3”], because this is how the ‘DSAns.keys’ variable comes out after converting it to a string.

However, making this change to the Excel file means that the PsychoPy program no longer works. The corresponding PsychoPy statement in the ‘code’ component of your ‘trial’ routine is:

if DSAns.keys == corrAns:
    DSAns.corr = 1
else:
    DSAns.corr=0

This needs to be changed to:

if ','.join(DSAns.keys) == corrAns:
    DSAns.corr = 1
else:
    DSAns.corr=0

These changes are sufficient to make your program work.

The fundamental issue here is that the ‘DSAns.keys’ variable has a different format in PsychoJS and PsychoPy. In PsychoJS, the ‘DSAns.keys’ variable matches 3,2,3 and ‘DSAns.corr’ is automatically set correctly without the need for any coding when ‘corrAns’ = 3,2,3. (This means that the PsychoJS code listed above that sets the value of ‘DSAns.corr’ is not actually required once the format of the ‘corrAns’ variable in the Excel conditions file has been changed to ‘3,2,3’ and this code can be omitted. I’ve left it in for clarity and for symmetry with the PsychoPy code.) Conversely, in PsychoPy, the ‘DSAns.keys’ variable matches [“3”,“2”,“3”] and ‘DSAns.corr’ is automatically set correctly without the need for any coding when ‘corrAns’ = [“3”,“2”,“3”]. But to get the program working in both PsychoPy and PsychoJS, you either need to use different code, or to maintain different Excel files for the PsychoPy and PsychoJS versions of the program. The former is the simpler solution, as Pavlovia synchs the Excel files unless they are indirectly referenced in the program by a variable.

2 Likes