这是google sheet [ESH-B1.1-考试2]
Google脚本是:examMakerQA
我是脚本新手。在工作表中,我希望在“多项选择题” [Col P to 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);
}
答案 0 :(得分:0)
当前,您正在将索引op
与D列中的答案键进行比较。
您需要做的是对P到Z列中与索引op
或TRUE
相对应的索引FALSE
的条目进行评估
为此,您可以按以下方式修改代码:
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);
}