首页 > 解决方案 > 如何使用 Apps 脚本随机化多个问题选择?

问题描述

我正在使用 Apps 脚本制作 Google 表单。Google 表单包含多项选择题。

因为我想让谷歌表格成为一个测验,所以我想随机化 MC 问题的选择顺序。

如何使用 Apps 脚本随机化选择/答案?

这是我的代码:

item=form.addMultipleChoiceItem();
    item.setTitle(Question);
    if (Ans == "A"){
    item.setChoices([item.createChoice(ChoiceA, true),item.createChoice(ChoiceB,false),item.createChoice(ChoiceC,false),item.createChoice(ChoiceD,false)]);};
        if (Ans == "B"){
    item.setChoices([item.createChoice(ChoiceA, false),item.createChoice(ChoiceB,true),item.createChoice(ChoiceC,false),item.createChoice(ChoiceD,false)]);};
        if (Ans == "C"){
    item.setChoices([item.createChoice(ChoiceA, false),item.createChoice(ChoiceB,false),item.createChoice(ChoiceC,true),item.createChoice(ChoiceD,false)]);};
        if (Ans == "D"){
    item.setChoices([item.createChoice(ChoiceA, false),item.createChoice(ChoiceB,false),item.createChoice(ChoiceC,false),item.createChoice(ChoiceD,true)]);};
    item.setPoints(1);
    item.setRequired(true);

标签: google-apps-scriptgoogle-formsgoogle-form-quiz

解决方案


function pickRandomQuestion(numberOfQuestions) {
  return Math.floor(Math.random()*(numberOfQuestions))+1;
}

返回 1 到问题数


推荐阅读