psychopy.org | Reference | Downloads | Github

Conditional branching based on Key Response - Psychopy code to JS

I have some Psychopy code for conditional branching based on keyboard responses of left or right keys.
The number of times participants have to push left or right changes, and is specified in 2 conditions columns in Excel (lockPress1 and lockPress2). Inputting lockPress 1 counts as a correct answer and determines which routine is next presented.
The rest of the code is to reset the keyboard in case participants push an unaccepted pattern of left and right keys. I realise there’s probably a much more elegant way of coding this, but this works for me!

I now need to translate this into JS Code in order to host the experiment on Pavlovia. I’m a bit stumped on this, even after checking through forum threads. Any help would be hugely appreciated!

if key_resp_12.keys == lockPress1 or key_resp_12.keys == lockPress2:
    continueRoutine = False 
    
elif key_resp_12.keys == ['left', 'right']:
    event.clearEvents(eventType='keyboard')
    key_resp_12 = event.BuilderKeyResponse()
    theseKeys = event.getKeys(keyList=['left', 'right'])
elif key_resp_12.keys == ['left', 'left', 'right']:
    event.clearEvents(eventType='keyboard')
    key_resp_12 = event.BuilderKeyResponse()
    theseKeys = event.getKeys(keyList=['left', 'right'])
elif key_resp_12.keys == ['right', 'left']:
    event.clearEvents(eventType='keyboard')
    key_resp_12 = event.BuilderKeyResponse()
    theseKeys = event.getKeys(keyList=['left', 'right'])
elif key_resp_12.keys == ['right','right', 'left']:
    event.clearEvents(eventType='keyboard')
    key_resp_12 = event.BuilderKeyResponse()
    theseKeys = event.getKeys(keyList=['left', 'right'])