samedi 31 octobre 2020

Google Forms Apps Script (.gs) function random assignment of users

I am a psychology student, with a little coding experience in a few different languages, but I'm a little, nix that, a lot rusty. I'm using Google Apps Script, trying to make it so that a Google Form can randomly assign participants into group A or B for a research project. This will be posted online so people can take it at any time, thus I won't be able to manually do it, it will have to be done programatically. I am using Google Sheets to store backend data, collecting email addresses to link data to specified user across sheets. Flow is such: Form 1 - link to informed consent on google drive for participants to download, sign, and upload, demographics data, and instructions walkthrough the next 4 forms they will be receiving. Click submit, and "submission received" ConfirmationMessage will contain link to either the group A form 2 or group B form 2. Form 2 will contain a link to an article to read, which they need to close after reading (I think we're going to have to be on the honor system here). I am collecting timestamp from submission of form 1 and timestamp of submission of form 2 to determine length of time spent reading the article. When they submit form 2, ConfirmationMessage needs to display link to form 3, a quiz on the article, rinse and repeat, each participant will read two articles. So, this is where I'm at, trying to random assign into group A or B...

         function onOpen() {
 var existingForm = FormApp.openById('1LWDhdp_xj7xXHDSHKFTgoARADPoZj5VXGo9H2p0rkNY');
    function pickRandom() {
      var wordsarray = ['heads','tails'];
      var randomnumber = Math.floor(Math.random() * wordsarray.length);
      console.log(wordsarray[randomnumber]);
    var answer = pickRandom(['heads','tails']);
if (answer === 'heads'){form.setConfirmationMessage('message1');}
if (answer === 'tails'){form.setConfirmationMessage('message2');}
      getConfirmationMessage();
      console.log(ConfirmationMessage);

I am getting nothing. I tried output to console to see what's going on, but no logs.




Aucun commentaire:

Enregistrer un commentaire