Reading/writing in csv files online

I’m working on a staircase paradigm I’m trying to get to run for online testing. Each participant does two blocks where they start from above and below threshold. The aim is to see whether the two staircases converge.

I would like to randomise where participants start from for each gender. So I have a file ‘Participants.csv’ where I store the gender of all participants who do the study. If the number of all females/males who did the study is divisible by 2, they start above, otherwise they start below.

My implementation works in Python, but I’m not sure how to translate the code below to JavaScript.

Can anyone help with translating this code to JavaScript?

Participants = open('Participants.csv', 'a')
Participants.write(Gender_key_resp.keys+'\n')
Participants.close()

Participants = open('Participants.csv', 'r')
Ppts_allLines = Participants.readlines()
Participants.close()

I’ve tried a variety of things, including this:

fs = require(‘fs’);
fs.write(‘resources/Participants.csv’, Gender_key_resp.keys, ‘a’);

Then downloaded require.js and put it in the directory with index.html, and then included in the body of the index.html:

But I get this error when I run online:

ReferenceError: require is not defined

Is there a way to store in the same file the gender of all the participants completing the study? Or to randomise such that half participants of the same gender start above the threshold and the other half start below?

I don’t believe this is possible online.

How to change the name of the data file when running online experiment

Best wishes,

Wakefield