TypeError: Cannot read property 'indexOf' of undefined

URL of experiment: https://pavlovia.org/run/knox/baddeley-et-al-1975-demo/html/

Description of the problem: I have an experiment that works properly via PsychoPy but I cannot get it to work on Pavlovia. I want to give participants 20 seconds to type responses on the screen. If they type “space” I want it to be like entering the word (proceed to next trial of entering the word). If they type “return” I want it to terminate the loop. I’ve attached the Each Frame portion of my code.

#Python that is working
if("return" in prac_resp.keys):
    prac_resp.keys.remove("return")
    
    pscreentext = ''.join(prac_resp.keys)
    thisExp.addData("pracrecall_resp",pscreentext)
    
    continueRoutine = False
    pracloop.finished=True
elif("space" in prac_resp.keys):
    prac_resp.keys.remove("space")
    
    pscreentext = ''.join(prac_resp.keys)
    thisExp.addData("pracrecall_resp",pscreentext)
    
    continueRoutine = False

pscreentext = ''.join(prac_resp.keys)

#JS that is giving me the error
var _pj;
function _pj_snippets(container) {
    function in_es6(left, right) {
        if (((right instanceof Array) || ((typeof right) === "string"))) {
            return (right.indexOf(left) > (- 1));
        } else {
            if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
                return right.has(left);
            } else {
                return (left in right);
            }
        }
    }
    container["in_es6"] = in_es6;
    return container;
}
_pj = {};
_pj_snippets(_pj);
if (((prac_resp.keys == undefined) && (prac_resp.keys.indexOf("return") > -1))) {
    trials.finished = true;
    prac_resp.keys.remove("return");
    pscreentext = prac_resp.keys.join('');
    thisExp.addData("pracrecall_resp", pscreentext);
} else {
    if (((prac_resp.keys == undefined) && (prac_resp.keys.indexOf("space") > -1))){
        prac_resp.keys.remove("space");
        pscreentext = prac_resp.keys.join('');
        thisExp.addData("pracrecall_resp", pscreentext);
        continueRoutine = false;
    }
}
pscreentext = prac_resp.keys.join('');

#Also for the Begin Routine, I have a syntax error for the JS side for my python:
timeStart = new util.Clock()
timeStart.getTime()

pscreentext = ''

The elif statement has translated a little strangely. At the moment, true is only returned if prac_resp_keys is undefined AND contains something to index. Try setting the code component to ‘both’ (rather than auto translate) and removing everything from && in the elif statement.

Also - I’m not sure that .join is a method of string objects in JS - you might need to use concat() instead

Hi Oli,

So for clarification, you’re suggesting:

if (((prac_resp.keys.indexOf("return") > -1))) {
    trials.finished = true;
    prac_resp.keys.remove("return");
    pscreentext = prac_resp.keys.concat('');
    thisExp.addData("pracrecall_resp", pscreentext)

Hi @pxi, were you able to get this to work in the end? I tried the experiment you link to locally and it seems to be running error free. Here to help in any case :blush:

Yes! I got a friend who knows JS to help. He confirmed my suspicion that something was wrong with the JS

Ah cool, good to hear, happy coding! :sun_with_face: