Reference Error: "" is not defined

URL of experiment: https://pavlovia.org/run/doladime/memory-scaffold-experiment/html/

Description of the problem: When I try to run my experiment online, I get the error that refillEmpty and checkText does not exist but I have the following code generated by the Auto -> JS translation
I am using a bit of code from the multiText demo and under the Begin Routine tab, it has:
‘’’ currentText = text;
captured_string = “”;
textComps = [text, otherText];
function checkText(text) {
if ((text.text === “Click to enter text…”)) {
text.text = “”;
}
return text;
}
function refillEmpty(currentText) {
for (var text, _pj_c = 0, _pj_a = textComps, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
text = _pj_a[_pj_c];
if (((text !== currentText) && (text.text.length === 0))) {
text.text = “Click to enter text…”;
}
}
}
‘’’
and under the Each Frame tab,
‘’‘var _pj;
function _pj_snippets(container) {
function in_es6(left, right) {
if (((right instanceof Array) || ((typeof right) === “string”))) {
return (right.indexOf(left) > (- 1));
} else {
if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
return right.has(left);
} else {
return (left in right);
}
}
}
container[“in_es6”] = in_es6;
return container;
}
_pj = {};
_pj_snippets(_pj);
for (var eachText, _pj_c = 0, _pj_a = textComps, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
eachText = _pj_a[_pj_c];
if (mouse.isPressedIn(eachText)) {
currentText = checkText(eachText);
}
}
for (var key, _pj_c = 0, _pj_a = event.getKeys(), _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
key = _pj_a[_pj_c];
if (_pj.in_es6(key, [“escape”])) {
core.quit();
} else {
if (_pj.in_es6(key, [“delete”, “backspace”])) {
captured_string = captured_string.slice(0, (- 1));
} else {
if (_pj.in_es6(key, [“space”])) {
captured_string = (captured_string + " ");
} else {
if (_pj.in_es6(key, [“lshift”, “rshift”, “up”, “down”, “left”, “right”])) {
} else {
captured_string = (captured_string + key);
}
}
}
}
}
currentText.text += captured_string;
captured_string = “”;
refillEmpty(currentText);
‘’’

Try to assign the function to refillEmpty/checkText in the js-Code.

checkText = function(text) {
    if ((text.text === “Click to enter text…”)) {
         text.text = “”;
    }
return text;
}

refillEmpty = function(currentText) {
    for (var text, _pj_c = 0, _pj_a = textComps, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
        text = _pj_a[_pj_c];
        if (((text !== currentText) && (text.text.length === 0))) {
            text.text = “Click to enter text…”;
        }
    }
}

You might have to switch to the “Both” option in the code component in order to be able to do that.

If the ReferenceError persists you could try to move the two functions to the Begin Experiment tab of the code component (but I think that won’t be necessary).

I am no expert in javascript but I assume that this issue has something to do with local/global scope in javascript.

@kimSpeck Hi! Thank you so much, the reference error still persisted after i moved it under the begin experiement tab, could the issue be with the way I’m calling the function? Here is how I am doing that:
" for (var eachText, _pj_c = 0, _pj_a = textComps, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
eachText = _pj_a[_pj_c];
if (eachText.contains(mouse_2) && mouse_2.getPressed()[0] === 1) {
// Do this
currentText = checkText(eachText);
pos = story_var.index(eachText.name);
}
}
“”
and

“refillEmpty(currentText);”