Shuffle answer properties

后端 未结 2 758
無奈伤痛
無奈伤痛 2020-12-22 01:45

I have to activate the properties to shuffle the question of a multiple choice type questoin, but I can\'t find the properties. I found this code that randomizes questions,

相关标签:
2条回答
  • 2020-12-22 02:29

    I believe that you have to randomize the options yourself with something like this:

    function randomizeArray(A) {
      var iA=A.slice();
      var oA=[];
      for(var i=0;i<A.length;i++) {
        var index=Math.floor(Math.random()*iA.length);
        oA.push(iA[index]);
        iA.splice(index,1); 
      }
      return oA;
    }
    
    0 讨论(0)
  • 2020-12-22 02:36

    Issuetracker:

    This isn't currently possible. Consider adding a star (on top left) to the following feature requests for Google to prioritize the issue:

    • https://issuetracker.google.com/issues/36764938

    • https://issuetracker.google.com/issues/64134484

    Partial worksround:

    Partial Workaround as already mentioned in this answer is to shuffle the array creating options and setback the array using setChoiceValues(). The drawback of such server side randomizing is

    • It can only be done whenever the server script runs and not when client opens the form

    • Even if you randomize each minute, it is possible that users opening the form simultaneously will see the same order of options

    Sample script:

    const form = FormApp.openById('/*form id*/');
    const item = form.addMultipleChoiceItem();
    item.setTitle('Car or truck?');
    const options = ['Truck', 'Car'];
    //Durstenfeld algo
    for (let i = options.length - 1; i > 0; i--) {
      let rand = Math.floor(Math.random() * i);
      [options[i], options[rand]] = [options[rand], options[i]];
    }
    item.setChoiceValues(options);
    
    0 讨论(0)
提交回复
热议问题