ReferenceError: can't find variable: interval

Hi! My experiment requires participants to press the space bar for each stimulus. However, when I pressed the space bar for the first stimulus, Pavlovia returned an error message: “ReferenceError: can’t find variable: interval.” I have defined a variable called “interval” in the JavaScript code. I’m wondering why this error is occurring.


When did you define the variable in relation to its use? Would you mind showing the relevant code, preferably in Python and PsychoJS?

Best wishes Jens

Hello @JensBoelte,

Thank you for your reply. The interval is embedded in each frame to make each trial length slightly different. The automatic translation from Python to PsychoJS didn’t work well, so we figured out how to define the interval using PsychoJS.

Here is the code in Python:


We have revised the code in JS and it works well:

const min = 0.25;
const max = 0.50;
const interval = Math.random() * (+max - +min) + +min;

The original translation was below and it gave the error.
interval = (Math.random.randint(250,500)/1000);
Please let us know if you have any further suggestion.



here my example I define in a Begin Experiment code-component

# Fixation cross duration
fixDurMin = 0.2 # minimum: 200 ms
fixDurMax = 0.5 # maximum: 500 ms

In the Begin Routine-component, I define:

# Fixation cross duration for this trial
fixDur = fixDurMin + (random() * (fixDurMax - fixDurMin)) # random between minimum and maximum
thisExp.addData('fixation_duration',fixDur) # document the duration in your logfile

This is auto-translated to:

fixDur = (fixDurMin + (Math.random() * (fixDurMax - fixDurMin)));
psychoJS.experiment.addData("fixation_duration", fixDur);

I use the variable fixDur as an argument to the Duration-parameter of a text-component.

which is followed by the stimulus

If you add your code to the Each Frame tab, then you trial-duration will be set new each frame!.

Best wishes Jens