Skip to main content

Feedback

In the event handler for the end scene's onSetup event, we calculate the accuracy of the participant's responses, as well as the response time for congruent and incongruent trials. We place this in the onSetup event handler so it is available as the end scene slides into view.

endScene.onSetup( ()=> {
const percentCorrect = game.data.trials.filter((trial) => trial.response_correct).length / numberOfTrials;
percentCorrectLabel.text = "Percent correct: " + percentCorrect.toFixed(2);

const congruentTrials = game.data.trials.filter((trial) => trial.congruent_stimulus);
let congruentRtSum = 0;
for (let i = 0; i < congruentTrials.length; i++) {
congruentRtSum = congruentRtSum + congruentTrials[i].response_time_ms;
}
const meanCongruentRt = congruentRtSum / congruentTrials.length;
congruentRtLabel.text = "Mean congruent rt: " + meanCongruentRt.toFixed(2);

const incongruentTrials = game.data.trials.filter((trial) => !trial.congruent_stimulus);
let incongruentRtSum = 0;
for (let i = 0; i < incongruentTrials.length; i++) {
incongruentRtSum = incongruentRtSum + incongruentTrials[i].response_time_ms;
}
const meanIncongruentRt = incongruentRtSum / incongruentTrials.length;
incongruentRtLabel.text = "Mean incongruent rt: " + meanIncongruentRt.toFixed(2);
});
Loading...