Age restriction code

URL of experiment: Pavlovia

Description of the problem: One of the pre-experiment questions is “Age in years”

I have tried several pieces of JavaScript code to quit experiment e.g.,

if int(expInfo[“Age in years”] >18
) {
psychoJS.quit({message: ‘Experiment terminated, Age out of range’});;

What I want to find is a piece of JS code that will terminate the experiment if the participant enters anything that is not a a string variable of the numbers between 18 and 120.

Any help would be appreciated


I think you just had a simple syntax error in the code snipped which you used beside the mobile browser detection and showed here.

so your code should work there fine
if you had the missing brackets and you do the correct int parse operation
for JS.

if(parseInt(expInfo[“Age in years”]) <18
) {
quitPsychoJS("Experiment terminated, Age out of range");

this should do the trick.

1 Like

Hi Luke,

Thanks for your response and sorry for the late reply.

I tried your code but it still seems to be doing nothing :-/

This code seems to be a mix of Python and JS, and has a bracket in the wrong position. You need to close int() before > 18.

Also do you want to quit when Age is 19+ ?

Add a console.log (print) command inside the brackets to check your quit code is being run at all, before wondering whether that is the source of the issue.