Randomise conditions nReps

Hello,

I tried the code below to randomise conditions. Then i put nRepsA or nRepsB in the nReps box in my loop. I saw this code in this video: WOW Tutorial PsychoPy3: Counterbalancing - YouTube

But when I run it, it says “nRepsA is not defined”. Any ideas?

Thanks,
Jan

randNum = Math.floor(Math.random() * 2)
if (randNum==0){
nRepsA = 1
nRepsB = 0
} else {
nRepsA = 0
nRepsB = 1
}

Try the following instead

nRepsA = 0;
nRepsB = 0;
randNum = Math.floor(Math.random() * 2);
if (randNum==0){
nRepsA = 1;
} else {
nRepsB = 1;
}

Personally I recommend coding in Python with an auto translate rather than JS directly.