Terminate the loop after 4 correct responses in a row in Pavlovia

Description of the problem:
Hi, I had no luck finding a way to terminate the loop after 4 correct responses in a row. Do you have any suggestions? my loop name is trials_voice, and my response component name is keyresp_sound.
So far I managed to terminate the task after they have 4 correct responses in total, but not in a row. Thank you.

js: Begin experiment
correctCount=0;


js: each frame


if (keyresp_sound.corr === 1) {
correctCount = correctCount + 1;
}

if ((correctCount === 4)) {
continueRoutine = false;
trials_voice.finished = true;
}

1 Like

You just need to set the counter back to 0 if they make a mistake:

if (keyresp_sound.corr === 1) {
    correctCount = correctCount + 1;
} else {
    correctCount = 0;
}
1 Like

Thank you so much. It fixed my problem.