简体   繁体   English

如何在 Google 测验中添加带有正确答案的多项选择题

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

This is the google sheet [ESH - B1.1 - Exam 2]这是谷歌表[ESH - B1.1 - 考试 2]

Google Script is: examMakerQA谷歌脚本是:examMakerQA

I am very new to scripting.我对脚本很陌生。 In the sheet, I wish to add True / False to the options of Multiple Choice Questions [Col P to Col Z].在表格中,我希望在多项选择题 [Col P 到 Col Z] 的选项中添加真/假。 So that I don't have to manually add correct answers in Google Form.这样我就不必在 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);
  
  }

Currently you are comparing the index op against the answer key in column D.目前,您正在将索引op与 D 列中的答案键进行比较。

What you need to do instead is to evaluate the entries in columns P to Z corresponding to the index op against TRUE or FALSE您需要做的是根据TRUEFALSE评估与索引op相对应的 P 到 Z 列中的条目

To do this you can modify your code as following:为此,您可以按如下方式修改代码:

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.

相关问题 如何在测验中为 checkboxGridItem 问题分配正确答案? - How to assign correct answers to checkboxGridItem questions in a quiz? Google表单作为多项选择测验 - 如何提供结果 - Google Forms as Multiple Choice Quiz - How to Provide Results 如何停用多选网格Google表单中的某些答案 - how to deactivate some answers in multiple choice grid google form 谷歌表格脚本 - 几个多项选择答案 - google sheets script - several multiple choice answers 如何在 Google 幻灯片中创建多项选择题 - How do I create a Multiple-Choice-Quiz within Google Slides 如何根据他们的测验答案向 Google Forms 响应者动态显示 HTML? - How to dynamically show HTML to Google Forms responder, based on their quiz answers? 如何从 Google 表格中的数据填充 Google 表单中的多项选择题 - How can I populate multiple choice questions in a Google Form from data within a Google Sheet 如何从Google表单多选网格中获得对问题的答案? - How can I get the response to the questions from a google forms multiple choice grid? 如何将多项选择题中的问题分开? - How do I keep the questions in the Multiple Choice divs separate? Google脚本通过电子邮件将表单答案和问题发送给用户 - Google Script to email form answers and questions to a user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM