【问题标题】:Shuffle answer properties随机播放答案属性
【发布时间】:2019-04-06 13:37:13
【问题描述】:

我必须激活属性来随机播放多项选择类型 questoin 的问题,但我找不到属性。我发现这段代码随机化了问题,而不是答案。

form.setShuffleQuestions(true); 

视觉组件的图片

【问题讨论】:

  • 您必须为您的问题提供更多上下文并修复拼写错误

标签: google-apps-script google-forms


【解决方案1】:

问题跟踪器:

目前这是不可能的。考虑在以下功能请求中添加星号(左上角),以便 Google 确定问题的优先级:

部分解决方法:

已经提到的部分解决方法in this answer 是随机排列数组创建选项并使用setChoiceValues() 回退数组。这种服务器端随机化的缺点是

  • 它只能在服务器脚本运行时完成,而不是在客户端打开表单时完成

  • 即使您将每分钟随机化,同时打开表单的用户也可能会看到相同的选项顺序

示例脚本:

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);

【讨论】:

    【解决方案2】:

    我认为您必须自己使用以下方式随机化选项:

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      相关资源
      最近更新 更多