ReferenceError: chars is not defined

URL of experiment: https://gitlab.pavlovia.org/obemar/masterarbeit
Project ID: 30428

Description of the problem:

When I run my language experiment online I get the “ReferenceError: chars ist not defined” message, which is confusing since I do not have a variable named chars (I had, but renamed them chars1 to chars3. The project is correctly synced to Pavlovia, not running some former version.)

I used chars1-3 to assign participants to version C or D (with a dummy loop) and within each version to group A or B (just counterbalancing the starting block).

The only chars I see in my code is in this part:
return chars.substr(Math.floor(Math.random() 2), 1);*
and I tried to change it to return chars1.substr(Math… for all three chars, but when running I don’t get past the participant code (it’s loading forever, no error message).

I made the experiment public and added the (most likely) faulty code beneath. I used some other code components too, but only if-statements and text input without a chars variable. So I guess it has to be in here somewhere:

Assignment to version C or D:
Beginn Experiment

chars1 = "CD";

function random_character() {
    chars1 = "CD";
    return chars.substr(Math.floor(Math.random()* 2), 1);
    }

VersionCD = random_character();

if ((VersionCD === "C")) {
    nReps_vC = 1;
    nReps_vD = 0;
} else {
    nReps_vC = 0;
    nReps_vD = 1;
}

V1 group A or B
Begin Routine

chars2 = "AB";

function random_character_vC() {
    chars2 = "AB";
    return chars.substr(Math.floor(Math.random()*2),1);
    }

condition = random_character_vC();

V2 group A or B:
Begin Routine

chars3 = "AB";

function random_character_vD() {
    chars3 = "AB";
    return chars.substr(Math.floor(Math.random()*2),1);
    }

condition = random_character_vD();

Additional info for understanding: I got the undeclared variable error message before and worked around this by adding that first line chars1=“CD” / chars2/3 = “AB” after some JS searching. I guess it works in the supposed way but am not sure if it’s the correct way to declare the variable. The error didn’t pop up after I added that part. For others in the forum the code seemed to work perfectly fine without that extra line. I have no idea why I needed it.

Thanks a lot for any help,
Maria

function random_character_vD() {
    chars3 = "AB";
    return chars.substr(Math.floor(Math.random()*2),1);
    }

Where are you defining chars? You seem to be defining chars1/2/3 and then returning chars

This is what I meant before, i tried returning chars1/2/3.substr() but that got me stuck after the participant code.
Strange enough I tried it a second time and now it works.

Thank you for pointing it out to me again.