簡體   English   中英

如何在 Google 測驗中添加帶有正確答案的多項選擇題

[英]How to add Multiple Choice Questions with Correct Answers in Google Quiz

這是谷歌表[ESH - B1.1 - 考試 2]

谷歌腳本是:examMakerQA

我對腳本很陌生。 在表格中,我希望在多項選擇題 [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 列中的答案鍵進行比較。

您需要做的是根據TRUEFALSE評估與索引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);  
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM