google-apps-script - 如何使用 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);
解决方案
function pickRandomQuestion(numberOfQuestions) {
return Math.floor(Math.random()*(numberOfQuestions))+1;
}
返回 1 到问题数
推荐阅读
- angular - 使用 flatMap 或地图在 Angular 中嵌套 http get 请求
- javascript - Parsley 验证字段总和
- javascript - 尝试从不同的数组创建独立的模态和发布信息
- unity3d - unity透明精灵渲染顺序
- apollo-client - 带变量的 apollo watch 方法
- php - 在 wordpress 上单击 php 中的测验的提交按钮后,不会显示 POST 的结果
- php - API 重定向 Flash 消息,消息未显示
- javascript - 使用for循环检查多个变量的内容
- python - 使用 discord.py,如何向名称中包含空格的用户添加角色?
- java - 必须设计一个使用 Arrays 和 Arraylists 打印全年结果的彩票程序