Checking that expInfo matchings trial list

Hello - I am working in JavaScript. Subjects enter a unique ID at the beginning of the experiment (in the expInfo pop-up box). I then want to use that ID to select a matching trial list. So, for instance, if subject enters ‘s101’ in the ID box, then they will get ‘s101_trial_list.csv’ for the experimental trials. If subjects enter an incorrect ID or one that does not have a corresponding trial list, they will get a ‘dummy’ trial file. Below is the code that is causing me trouble (automatically converted from psychopy).

let expInfo = {‘age’: ‘’, ‘gender (m/f)’: ‘’, ‘worker_ID’: ‘’};

var trialLists = [‘s101’, ‘s102’];
var dummyFile = ‘s103_trial_list.csv’;
var pathway = ‘’;
for (var x, _pj_c = 0, _pj_a = trialLists, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
x = _pj_a[_pj_c];
if ((x === expInfo[‘worker_ID’])) {
pathway = (String(expInfo[‘worker_ID’]) + ‘_trial_list.csv’);
break;
} else {
pathway = dummyFile;
}
}

Basically, any ID that I enter at the beginning is shown the dummy trial list. However, when an ID is entered manually into the blank ID field (thus, automatically filling in the ID box at the beginning of the exp), the correct trial file is selected. Therefore, I think it may have something to do with how the ID is being saved after it is entered by subjects. Can anyone please help with this issue and perhaps direct me to some helpful resources? Thanks!

Hi! Looking at your code, I can imagine two things that could go wrong (perhaps both):

  1. The part that belongs to the if statement isn’t executed. You could check this by printing something to the browser console via console.log.
  2. The part that belongs to the if statement is executed, but the conditions file isn’t set to pathway. I would guess that this can be challenge anyways, since it takes some extra steps to download a custom conditions file via PsychoJS. Before we go here let’s first check if solving #1 helps you out

Best, Thomas