Syntax JS error "Identifier 'asarray' has already been declared"

Hi all,

I am stuck on initializing experiment, because there seems to be a problem with my code component. I am randomizing conditions in one of my routines and use code A for this purpose (see below code A) and it works fine. However, I also have another piece of code for the same purpose (to randomize another set of conditions in a different routine). And this piece of code causes the error (code B, see below). Do you have any ideas how I can change this code so the error doesn’t persist?

Code A:

Blockquote

function random_character() {
var chars = “ABCD”;
return chars.substr( Math.floor(Math.random() * 4), 1);
}

condition = random_character();

Blockquote


Code B:

Blockquote

function random_character() {
var chars = “EFG”;
return chars.substr( Math.floor(Math.random() * 3), 1);
}

condition2 = random_character();

Blockquote

You have given two different functions the same name. Either use different names, use the same function in both cases (using the string as the input) or don’t define functions at all.

Thanks a lot! I tied to rename it, but it didn’t help:

function random_character2() {
var chars = “123”;
return chars.substr( Math.floor(Math.random() * 3), 1);
}

condition2 = random_character2();

Use an incognito tab to check you’re running the latest version.

Thank you, I tied that and also using other browsers - but still stuck on initializing experiment! how strange

I’m sure that the issue is with that code component, because when I delete it, experiment runs without a problem.

Math.floor() should contain one parameter, not two. Try removing ,1

Thank you! Unfortunately removing 1 didn’t solve the issue. So what I did is I deleted one of my code components. Instead of this component (which randomized instructions between participants) I created a loop which randomly presents one of my conditions and stops.