| Reference | Downloads | Github

ReferenceError: "range is not defined"

Hello Pavlovians,

I am getting an error just after beginning the experiment to pilot it:
ReferenceError: "range is not defined"
However, from what I can see on the crib sheet and elsewhere, the range() function should be supported.

From the browser’s debugger the messages, I found that the error is on the line:

  listOrder = list(range(nBlocks));

where nBlocks is an integer. This seems like a very simple operation-- does anyone know what’s going on?

I’m not familiar with the list function.

However, my experience with the Math functions is that sometimes they auto translate and sometimes not. I think that they fail when buried within other functions.

What comes up on the JS side if you just write a = range(b) to see if you need to make an edit

That makes sense; a = range(b) translates to

a = range(b);

So maybe I need to put something in code_JS at the beginning of the experiment?
Something like in this thread?

function range(size, startAt = 0) {
    return [...Array(size).keys()].map(i => i + startAt);
1 Like

If range is unchanged then maybe the problem is with nBlocks. Is that defined to be a value of at least 1 by the time this code is first encountered?

Thanks @wakecarter, nBlocks is well defined and the above JS code did work for me. On to the next error… :slight_smile: