如何在 Google 测验中添加正确答案的多项选择题
How to add Multiple Choice Questions with Correct Answers in Google Quiz
这是 google sheet [ESH - B1.1 - 考试 2]
Google 脚本是:examMakerQA
我对脚本编写还很陌生。在 sheet 中,我希望将 True / False 添加到多项选择题 [Col P 至 Col Z] 的选项中。这样我就不必在 Google 表格中手动添加正确答案。
//Make Multiple-Choice question
function makeMultipleCQ(d, form){
var mcItem = form.addMultipleChoiceItem();
mcItem.setTitle(d[1]);
if(d[2] !== "N"){mcItem.setPoints(d[2])};
if(d[4] === "Y"){mcItem.setRequired(true);}
//Filter blank cells
var options = d.splice(5,10);
var options = options.filter(function(x){return x !== ""});
var corrects = d.splice(15, 20); // data with true, false
var corrects = options.filter(function(x){return x !== ""});
//Loop through options and add to question
**var ch = options.map(function(option, op){
var tf = false;
if(op === d[3]){tf = true};
return mcItem.createChoice(option, tf)**
});
mcItem.setChoices(ch);
var correctFeedback = FormApp.createFeedback()
.setText(d[3])
.build();
mcItem.setFeedbackForCorrect(correctFeedback);
}
目前您正在将索引 op
与 D 列中的答案键进行比较。
您需要做的是根据 TRUE
或 FALSE
[=22 评估对应于索引 op
的列 P 到 Z 中的条目=]
为此,您可以按如下方式修改代码:
function makeMultipleCQ(d, form){
var mcItem = form.addMultipleChoiceItem();
mcItem.setTitle(d[1]);
mcItem.setTitle(d[1]);
if(d[2] !== "N"){mcItem.setPoints(d[2])};
if(d[4] === "Y"){mcItem.setRequired(true);}
//Filter blank cells
var options = d.splice(5,10);
var options = options.filter(function(x){return x !== ""});
//after the previos splice the original array and consequently the indeices has been modified
var ops = d.splice(5,10);
var ops = ops.filter(function(x){return x !== ""});
//Loop through options and add to question
var ch = options.map(function(option, op){
var tf = ops[op];
return mcItem.createChoice(option, tf);
});
mcItem.setChoices(ch);
var correctFeedback = FormApp.createFeedback()
.setText(d[3])
.build();
mcItem.setFeedbackForCorrect(correctFeedback);
}
这是 google sheet [ESH - B1.1 - 考试 2]
Google 脚本是:examMakerQA
我对脚本编写还很陌生。在 sheet 中,我希望将 True / False 添加到多项选择题 [Col P 至 Col Z] 的选项中。这样我就不必在 Google 表格中手动添加正确答案。
//Make Multiple-Choice question
function makeMultipleCQ(d, form){
var mcItem = form.addMultipleChoiceItem();
mcItem.setTitle(d[1]);
if(d[2] !== "N"){mcItem.setPoints(d[2])};
if(d[4] === "Y"){mcItem.setRequired(true);}
//Filter blank cells
var options = d.splice(5,10);
var options = options.filter(function(x){return x !== ""});
var corrects = d.splice(15, 20); // data with true, false
var corrects = options.filter(function(x){return x !== ""});
//Loop through options and add to question
**var ch = options.map(function(option, op){
var tf = false;
if(op === d[3]){tf = true};
return mcItem.createChoice(option, tf)**
});
mcItem.setChoices(ch);
var correctFeedback = FormApp.createFeedback()
.setText(d[3])
.build();
mcItem.setFeedbackForCorrect(correctFeedback);
}
目前您正在将索引 op
与 D 列中的答案键进行比较。
您需要做的是根据 TRUE
或 FALSE
[=22 评估对应于索引 op
的列 P 到 Z 中的条目=]
为此,您可以按如下方式修改代码:
function makeMultipleCQ(d, form){
var mcItem = form.addMultipleChoiceItem();
mcItem.setTitle(d[1]);
mcItem.setTitle(d[1]);
if(d[2] !== "N"){mcItem.setPoints(d[2])};
if(d[4] === "Y"){mcItem.setRequired(true);}
//Filter blank cells
var options = d.splice(5,10);
var options = options.filter(function(x){return x !== ""});
//after the previos splice the original array and consequently the indeices has been modified
var ops = d.splice(5,10);
var ops = ops.filter(function(x){return x !== ""});
//Loop through options and add to question
var ch = options.map(function(option, op){
var tf = ops[op];
return mcItem.createChoice(option, tf);
});
mcItem.setChoices(ch);
var correctFeedback = FormApp.createFeedback()
.setText(d[3])
.build();
mcItem.setFeedbackForCorrect(correctFeedback);
}