psychopy.org | Reference | Downloads | Github

Online error reading JS code for customised mouse response

URL of experiment: https://run.pavlovia.org/KDaughters/validation-study-1/html/

Description of the problem:
I’m trying to incorporate participants consent at the beginning of an online study. Participants must answer three consent items before beginning the study. If they select a cross for any of the consent items the study should quit so that they cannot proceed. To do this I have created ‘buttons’ using the mouse component and a code component to quit the study based on their mouse response.

The study works fine in builder, but two things happen when I try to run it online: 1) the ‘buttons’ don’t work in safari, they aren’t recognised so the study gets stuck; 2) if I run it in chrome, the buttons work fine, but it seems to ignore the code and carry on to the next routine regardless of response.

I suspect this is due to errors in my attempt to convert python into JS. My code is below:

End Routine - Python:
print (consent_1_resp.clicked_name)

if consent_1_resp.clicked_name == [‘cross_1’]:
core.quit()

End Routine - JS:
console.log (consent_1_resp.clicked_name);

if (consent_1_resp.clicked_name == [‘cross_1’]){
core.quit();
}

I’ve used other relevant topics to solve some problems (I’m no longer getting the “failed to parse as JS” error, or getting stuck on the ‘initializing experiment’ page, but struggling on how else to edit the JS. Any suggestions would be much appreciated!

Katie

Hi @KDaughters, looks like this is an issue in comparing arrays (its not as easy as with Python). An alternative method to check whether the name of the cross is in the clicked names array is to use the array method includes (notice also the core.quit method has also changed):

if (consent_1_resp.clicked_name.includes("cross_1")) {
    return psychoJS.quit('You did not consent. Goodbye!', false)
}

Hi @dvbridges, thanks so much, that works perfectly (in chrome).

Do you happen to know why it doesn’t work in safari? It’s not a problem, just curious for future reference.