Ending the experiment if participant clicks on "no consent" text with mouse click

OtherRaceEffect_Program.psyexp (127.6 KB)

Description of the problem:
Hello, I am trying to include code for an online experiment so that the experiment automatically closes if participants do not agree to participate. Specifically, if they use the mouse (which in my experiment is called Mouse_4) and they click on text labelled “No_Consent_Button” as opposed to text labelled “Consent_Button.” After reading around, this is the code I have created so far, but it does not work:

Code Type: JS in the End Routine Tab

if Mouse_4.ispressedin(No_Consent_Button): 
{ return psychoJS.quit('you did not consent. goodbye!', false) }

The experiment just continues even if they press no consent.

Any help would be greatly appreciated.

Hi @plkemp, apologies for the late reply. There is a syntax error in your ‘code_consent’ component. Could you try pasting in the following snippet or running the edited .psyexp attached and post back if the problem remains? Thanks, s.

if (mouse_4.isPressedIn(no_consent_button)) {
  return psychojs.quit('you did not consent. goodbye!', false);

OtherRaceEffect_Program.psyexp (127.5 KB)