Skipping the loop according to the accuracy rate

OS** (e.g. Win10): Win11

PsychoPy version** (e.g. 1.84.x): v2021.2.3

Online experiment

There are two parts of the experiment. The first part is for participants to practice, which includes two loops shown in the following picture. There are practice sentences and 15 questions (total five trials and 3 types of questions for each trial).


(Picture 1: the simplified version of the practice part)

I hope that participants can enter the second part if their accuracy rate achieve 90% in the practice part:
If the participant’ accuracy rate hasn’t reached 90%, they will repeat the first loop.
If the participant’ accuracy rate reached 90%, they will continue and skip the loop ”trials_2”.

Then, I added a code in the routine “prac_feedback_”. However, it doesn’t work. The error said “’append’ has not been defined”

(Picture 2: the code in the routine “prac_feedback_”)

How can I revise this code to achieve my purpose of this online experiment?

Any responses are appreciated!

Hi @gxwynl,

it says that this is an “online experiment”, but your screenshot shows python code. For online experiments, you have to use javascript.

Best,
Adrian

Hi, Adrian,

Got it! Thanks a lot!
Btw, is the code itself correct? Can I use “append” here? It seems that the computer still cannot recognize it even though I changed the type of code.

Best,
Nancy

Hi Nancy,

I am not a javascript-pro myself, so I also would have to google “append”. The if-else definitely needs some adjustment. In my view, the simplest way would be to just add up your .corr variables to a cumulative score at the end of the routine. This score you could then (re)set to 0 at the start of the block. Something like this:

# In End Routine:
prac_corrCount = prac_corrCount + resp_prac_question1.corr + resp_prac_question2.corr + resp_prac_question3.corr

if(prac_corrCount >= 13){trials_2.finished = true; feedback  = "X"}else{feedback = "Y"}

Hope that helps,
Adrian

If you set the :code: Code component to “auto Py->JS” then it will attempt to translate it for you, but I believe the JS equivalent of .append is .push

Hi, Adrian,
Thanks for your reply and patience. It is really helpful. Best wishes!

Nancy

Yes it’s true. Thanks a lot!