Hi,
I am trying to get my experiment online. Unfortunately, I am very unfamiliar with JS and currently running into some issue regarding the improper translation from Python to JS.
URL of experiment: Katharina Weiss / SC · GitLab
Description of the problem:
I have an empty textbox component (textbox_E1) which should receive keyboard input from the participant. Via the code component I only want to allow numbers.
Python Code:
keys = k.getKeys(keyList = [0,1,2,3,4,5,6,7,8,9, 'space']);
for ch in textbox_E1.text:
textbox_E1.text = "".join([ch for ch in textbox_E1.text if ch in ["0","1","2","3","4","5","6","7","8","9"]]);
textbox_E1.text = textbox_E1.text.replace(' ', '')
JS Code:
keys = k.getKeys({"keyList": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "space"]});
for (var ch, _pj_c = 0, _pj_a = textbox_E1.text, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
ch = _pj_a[_pj_c];
textbox_E1.text = (function () {
var _pj_d = [], _pj_e = textbox_E1.text;
for (var _pj_f = 0, _pj_g = _pj_e.length; (_pj_f < _pj_g); _pj_f += 1) {
var ch = _pj_e[_pj_f];
if (_pj.in_es6(ch, ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"])) {
_pj_d.push(ch).join("");
}
}
return _pj_d;
}
.call(this));
textbox_E1.text = textbox_E1.text.replace(" ", "");
}
I am getting the following error: TypeError: _pj_d.push(…).join is not a function
I’ve read the crib sheet which pointed me to use array.join(“delimeter”); in the JS code. Have I not implemented this correctly?
I am happy to receive any input!
Thanks in advance!
Best,
Kathi