.join not supported on online study

Description of the problem:
I coded my experiment through Builder on Psychopy and I added a code to only allow specific keys on the TextBox response (and it worked when I launch the experiment through Psychopy).
Here is the code used in Psychopy:

TextBox_A_B3_Eq.text = “”.join([ch.upper() for ch in TextBox_A_B3_Eq.text if ch.lower() in [“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “0”]])

It has been automatically translated in java like this:

_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);
TextBox_A_B3_Eq.text = “”.join(function () {
var _pj_a = , _pj_b = TextBox_A_B3_Eq.text;
for (var _pj_c = 0, _pj_d = _pj_b.length; (_pj_c < _pj_d); _pj_c += 1) {
var ch = _pj_b[_pj_c];
if (_pj.in_es6(ch.lower(), [“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “0”])) {
_pj_a.push(ch.upper());
}
}
return _pj_a;
}
.call(this));

So I know that Java do not support this “.join” but how can I change that on the java translation?

Thank you for your help!

Mélanie

Check my crib sheet for the manual translation of join.

Thank you for the manual. However, I think that my code is not appropriate for pavlovia, now I have the following message : “ch.lower is not a function”

What I try to do is to only allow numbers in the textbox. It works fine on Psychopy but not online unfortunately.

here is the code for psychopy :
TextBox_A_B3_Eq.text = “”.join([ch.upper() for ch in TextBox_A_B3_Eq_2.text if ch.lower() in [“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “0”]])

And here is the code for pavlovia:
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);
TextBox_A_B3_Eq.text = (function () {
var _pj_a = , _pj_b = TextBox_A_B3_Eq_2.text;
for (var _pj_c = 0, _pj_d = _pj_b.length; (_pj_c < _pj_d); _pj_c += 1) {
var ch = _pj_b[_pj_c];
if (_pj.in_es6(ch.lower(), [“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “0”])) {
_pj_a.push(ch.upper()).join("");
}
}
return _pj_a;
}
.call(this));

Thank you for your help :slight_smile:

.lower is also on my crib sheet. It translates to .toLowerCase

However, it’s not necessary for digits anyway.

Have a look at my digit span online demo.