Skip to specific routine based on response

Hello,

I want to make it so that if a participant presses any key other than ‘3’ on a specific screen, they are directed to a screen saying that they failed to answer the question correctly and make it so that there is no exit from the screen (so no available key presses or time limit) but the experiment is not terminated. If the participant presses the ‘3’ key, I want them to be able to go onto the next routine in the experiment.

However, I am a complete novice and do not know how to achieve this. Thank you for any help!

Delete the keyboard component and add a code component to your routine.

Begin Routine

screenLocked=0

Each Frame

keys=getKeys()
if len(keys):
     if '3' in keys and screenLocked==0:
          continueRoutine=False
     else:
          text_1.setText('You failed to answer the question correctly. The experiment has been terminated')
          screenLocked=1

Change text_1 to the name of your text component.

N.B. The above is Python code which should auto translate to JS correctly.

Thanks! I do have a follow-up question. So the screen I am talking about appears third in my loop and I need the first two screens to accept key presses of ‘1’, ‘2’, ‘3’, ‘4’, and ‘5’, what should I do to accommodate both?