Hi everybody!

My experiment is stuck on “Initializing the experiment” and I think, I found the problem.

I’m using a range function and as I read in the crib sheet (https://docs.google.com/document/d/13jp0QAqQeFlYSjeZS0fDInvgaDzBXjGQNe4VNKbbNHQ/edit#heading=h.xamc2didaojg), the auto translation does not work. My problem is, that I don’t get the “correct version” of the crib sheet to run.

I want to draw items out of two different lists depending on the accuracy of the current trial to create a variable ITI (intertrial interval so that the time passing by from the prior to the next trial depends on the accuracy). This is how my Python code looks like (which works fine offline):

```
#Determine random ITI depending on accuracy of the current trial
step_size = 1
start_val_correct = 1
end_val_correct = 3
start_val_wrong = 9
end_val_wrong = 12
l_correct = range(start_val_correct, end_val_correct, step_size)
l_wrong = range(start_val_wrong, end_val_wrong, step_size)
#shuffle list
import random
ITI_correct_big = random.choice(l_correct)
ITI_wrong_big = random.choice(l_wrong)
ITI_correct = ITI_correct_big/10
ITI_wrong = ITI_wrong_big/10
```

As you can see the lists to choose from vary either from 1 to 3 or from 9 to 12 with step size 1.

Here is what I tried to implement the correct function of the crib sheet using these forum entries

But it’s not working, still stuck on “initializing the experiment”:

```
var ITI_correct, ITI_correct_big, ITI_wrong, ITI_wrong_big, end_val_correct, end_val_wrong, l_correct, l_wrong, start_val_correct, start_val_wrong, step_size;
step_size = 1;
start_val_correct = 1;
end_val_correct = 3;
start_val_wrong = 9;
end_val_wrong = 12;
range_corr = function range(size, startAt = 1) {
return [...Array(3).keys()];
}
range_wrong = function range(size, startAt = 9) {
return [...Array(12).keys()];
}
random = Math.random;
ITI_correct_big = random.choice(range_corr);
ITI_wrong_big = random.choice(range_wrong);
ITI_correct = (ITI_correct_big / 10);
ITI_wrong = (ITI_wrong_big / 10);
```

I also tried to work around the range function by creating a list of the elements, so that the random function can pick from the list directly. But it’s not working either.

```
range_corr, range_wrong, random, ITI_correct, ITI_wrong;
range_corr = [0.1, 0.2, 0.3];
range_wrong = [0.9, 1.0, 1.1, 1.2];
random = Math.random;
ITI_correct = random.choice(range_corr);
ITI_wrong = random.choice(range_wrong);
```

Additionally, I found this post: Code conversion Jittered ITI in PsychoJS

I added my code accordingly, but I’m still stuck on the initializing (all is in Begin Routine now).

```
iti_correct, iti_wrong;
randint = function(min, maxplusone) {
return Math.floor(Math.random() * (maxplusone - min) ) + min;
}
round = function(num, n=0) {
return +(Math.round(num + ("e+" + n)) + ("e-" + n));
}
iti_correct = (randint(0, 201)+100)/1000;
iti_correct = Math.round(iti_correct(iti_correct, 1);
iti_wrong = (randint(0, 301)+900)/1000;
iti_wrong = Math.round(iti_wrong(iti_wrong, 1);
if ((mt_key_resp_t1.corr && mt_key_resp_t2.corr)) {
mt_iti_dur = iti_correct;
} else {
mt_iti_dur = iti_wrong;
}
```

How do I correctly implement the range function or the drawing from the list in JavaScript? Any help is highly appreciated!

Thanks!