URL of experiment: https://run.pavlovia.org/LisaMarieke/slotmachinetest/
Description of the problem:
Hi,
I have a problem when running my study online - I think my general problem is that I have a few custom code components in my experiment which I tried to translate from python to javascript, unsuccessfully however.
The first code components terminates the experiment when participants do not perform well enough on a quiz. If they score below 80%, then the entire experiment is terminated and they only see the last thank you slide. If they do well enough then they can continue with the experiment.
In the ‘begin experiment’ box I have this python code:
respcorrs = []
minNrPractice = 10 # min number of trials to practice
considerNrTrials = 10 # number of trials to consider for accuracy calculation
minAccuracy = 0.8
and translated that to this javascript code:
respcorrs = [];
minNrPractice = 10; // min number of trials to practice
considerNrTrials = 10; // number of trials to consider for accuracy calculation
minAccuracy = 0.8;
In the ‘End Routine’ box I have this python code:
respcorrs.append(QuizzResp.corr)
if len(respcorrs) >= minNrPractice:
respcorrsRecent = respcorrs[-considerNrTrials:]
respcorrsSum = sum(respcorrsRecent)
accuracy = float(respcorrsSum)/considerNrTrials
if accuracy < minAccuracy:
print('not good enough')
RunStop = RunRoutine_3
else:
RunStop = RunRoutine_2
which works fine and does what its supposed to do. The variable RunStop is used by the second loop, which may not get executed and ‘RunRoutine’ are column names in an excel table that is used by the outermost loop.
I tried to translate that to Javascript, however it doesn’t work. When I try it out, then the experiment just goes on.
respcorrs.push(QuizzResp.corr); // assumes your keyboard component is called "resp"
if (respcorrs.length >= minNrPractice){
accuracy = respcorrs/considerNrTrials;
if (accuracy < minAccuracy) {
RunStop = RunRoutine_3;
} else {
RunStop = RunRoutine_2;
}
}
I have also tried it very similar to the python code, but I have received an for the reduce command as well as parse command.
if (respcorrs.length >= minNrPractice){
respcorrsRecent = respcorrs[-considerNrTrials];
respcorrsSum = respcorrsRecent.reduce(respcorrsRecent);
accuracy = parse.Float(respcorrsSum)/considerNrTrials;
if (accuracy < minAccuracy) {
RunStop = RunRoutine_3;
} else {
RunStop = RunRoutine_2;
}
}
I have tried my best to come up with the right way to write this in javascript but I just do not seem to get it.
Thank you very, very much already for your help.