Description of the problem: I’m helping an undergraduate student to build a PsychoPy3 experiment and I encountered a strange issue. The PY version of the experiment runs nicely, and I was working through some bugs in my JS code when I came across this error in the console:
Uncaught SyntaxError: Illegal return statement refering to line:
/run/Jordan_Gallant/megansMazeTask/html/megansMazeTask.js:727
The line in question is the second line of the following:
if (psychoJS.experiment.experimentEnded || psychoJS.eventManager.getKeys({keyList:[‘escape’]}).length > 0) { return psychoJS.quit(‘The [Escape] key was pressed. Goodbye!’, false);
}
I was quite confused because I checked other experiments that are currently working and the same line appears. I’m not sure why this is happening. I suspect it has something to do with the custom JS code elements in the experiment, but that’s a vague guess at best.
The error (in firefox) says SyntaxError: return not in function because the call to return must be inside some function. In your case it should be inside the mazeTaskRoutineEachFrame() function.
Then you have to think, “why is it not inside that function?”
The issue is that the function is defined by the { }. If your inserted code has an extra } somewhere then it will end the function and then return is sitting outside the function.
I’ve moved your JS file to an editor (e.g. sublime) that shows up which brackets are matching which others and tracked it down to your code here:
Thanks for your help @jon, I’m glad it’s a quick fix. I’m still getting used to the JS syntax.
I’ve been using the Chrome console to debug experiments. Do you have any other recommendations for this that might catch syntax errors like the one above. That would save me some time.