Constraint typed text to a range of number

Description of the problem:
I am doing an attentional task in which it is required to count a certain number of irregular sound that they have to report at the end of the experiment. I’ve used the code below found in the inputtext task on pavlovia : https://gitlab.pavlovia.org/demos/textinput.

Here is the code in the frame tab :

let theseKeys = psychoJS.eventManager.getKeys();
if (theseKeys.length > 0) {  // at least one key was pressed
  textAdd = theseKeys[theseKeys.length-1];
  }

if (textAdd === 'return') {
    textAdd = '';  // Add nothin
    continueRoutine = false;  // End routine (if that is what you want)
} else if (textAdd === 'space') {
    textAdd = ' ';  // Add a space
} else if (textAdd === 'backspace') {
    text.text = text.text.slice(0, -1);
    textAdd = undefined;
} else if (['lshift', 'rshift'].includes(textAdd)) {
    modify = true;
} else if (textAdd !== undefined) {
    if (modify) {
        text.text = text.text + textAdd.toUpperCase();
        modify = false;
    } else {
        text.text = text.text + textAdd
    }
    textAdd = undefined;
}

I would like to constraint the possible response to a range of numbers, from 0 to 300. To do so, I’ve thought to add a boolean function into the return part as here :

if (textAdd === 'return') {
    if (text.text === *numbers between 0 to 300*) {  
    continueRoutine = false;  // End routine (if that is what you want
    textAdd = '';  // Add nothin
    } else {
    continueRoutine = true; 
    textAdd = '';  // Add nothin
    }

However, I don’t know the correct syntax to define a variable that says from 0 to 300. Anyone would know ?

Thanks a lot in advance,
Patrick

if int(text.text) >= 0 and int(text.text) <= 300:
1 Like

Thanks a lot !

Although, the code didn’t work with the auto-translate into js, it gave me the Number.parsInt function.
I found the correct syntax in the end in java which is very similar to the one in python :

if ((text.text) >= 0 && (text.text) <= 300) {