“Google表格测验中的错误在“答案反馈”中”

huangapple go评论71阅读模式
英文:

Google form quiz error in "ans feedback "

问题

我已经为Google表单“QUIZ”创建了一个Appscript。将默认问题分值保留为1分。默认情况下,所有问题都需要回答。选择问题并设置答案键。我遇到了以下错误,无法为问题设置反馈:

8:59:49 PM 错误
异常:参数(字符串)与FormApp.MultipleChoiceItem.setFeedbackForIncorrect的方法签名不匹配。
createPMPQuiz @ Quiz.gs:18

以下是Google Appscript:

function createQuiz() {
  var form = FormApp.create('Quiz');

  // 启用测验设置
  form.setIsQuiz(true);

  // 添加第一个问题
  var question1 = form.addMultipleChoiceItem();
  question1.setTitle('RGB代表什么?');
  question1.setChoices([
    question1.createChoice('Rod,Glue,Blue'),
    question1.createChoice('Red,Green,Blue', true),
    question1.createChoice('Reed,Green,Blur'),
    question1.createChoice('Rose,Girl,Bear')
  ]);
  question1.setRequired(true);
  question1.setPoints(1);
  question1.setFeedbackForIncorrect('错误。请再试一次。');
  question1.setFeedbackForCorrect('正确!Red,Green,Blue。');

  // 发布表单
  var formUrl = form.getPublishedUrl();
  Logger.log('表单网址:' + formUrl);
}

希望这可以帮助您解决问题。

英文:

I have created an Appscript for a Google form "QUIZ". Keeping the default question point value as 1 point. Questions are required by default for all questions. Selects the questions and set the answer key. I am getting the below error and I am not able to set the feedback for the questions:

8:59:49 PM	Error	
Exception: The parameters (String) don't match the method signature for FormApp.MultipleChoiceItem.setFeedbackForIncorrect.
createPMPQuiz	@ Quiz.gs:18

Below is the Google Appscript:

function createQuiz() {
  var form = FormApp.create('Quiz');

  // Enable Quiz settings
  form.setIsQuiz(true);

  // Add the first question
  var question1 = form.addMultipleChoiceItem();
  question1.setTitle('RGB stands for _______________.');
  question1.setChoices([
    question1.createChoice('Rod,Glue,Blue'),
    question1.createChoice('Red,Green,Blue', true),
    question1.createChoice('Reed,Green,Blur'),
    question1.createChoice('Rose,Girl,Bear')
  ]);
  question1.setRequired(true);
  question1.setPoints(1);
  question1.setFeedbackForIncorrect('Incorrect. Please try again.');
  question1.setFeedbackForCorrect('Correct! Red,Green,Blue.');

  // Publish the form
  var formUrl = form.getPublishedUrl();
  Logger.log('Form URL: ' + formUrl);
}

答案1

得分: 1

我写这个答案作为一个社区维基,因为它是从评论部分摘录的,旨在为问题提供适当的回答。

正如@Cooper在评论中提到的,setFeedbackForIncorrectsetFeedbackForCorrect 需要一个 QuizFeedback,文档有点过时,但我根据它制作了一个可工作的代码版本:

function createQuiz() {
  var form = FormApp.create('Quiz');

  // 启用测验设置
  form.setIsQuiz(true);

  // 添加第一个问题
  var question1 = form.addMultipleChoiceItem();
  question1.setTitle('RGB 代表什么?');
  question1.setChoices([
    question1.createChoice('罗德,胶水,蓝色'),
    question1.createChoice('红色,绿色,蓝色', true),
    question1.createChoice('瑞德,绿色,模糊'),
    question1.createChoice('玫瑰,女孩,熊')
  ]);
  question1.setRequired(true);
  question1.setPoints(1);
  question1.setFeedbackForIncorrect(
    FormApp.createFeedback().setText('回答错误,请再试一次。').build());
  question1.setFeedbackForCorrect(
    FormApp.createFeedback().setText('回答正确!红色,绿色,蓝色。').build());

  // 发布表单
  var formUrl = form.getPublishedUrl();
  Logger.log('表单链接:' + formUrl);
}

Google 的文档 使用了 setDisplayText,而 Apps Script 只接受 setText,这已经在 这里 报告过了。

英文:

I'm writing this answer as a community wiki, since it was taken from the comments section, in order to provide a proper response to the question.

As @Cooper mentioned in the comments, the setFeedbackForIncorrect and setFeedbackForCorrect require a QuizFeedback, the documentation is a little outdated but I made a working version of your code based on it:

function createQuiz() {
  var form = FormApp.create('Quiz');

  // Enable Quiz settings
  form.setIsQuiz(true);

  // Add the first question
  var question1 = form.addMultipleChoiceItem();
  question1.setTitle('RGB stands for _______________.');
  question1.setChoices([
    question1.createChoice('Rod,Glue,Blue'),
    question1.createChoice('Red,Green,Blue', true),
    question1.createChoice('Reed,Green,Blur'),
    question1.createChoice('Rose,Girl,Bear')
  ]);
  question1.setRequired(true);
  question1.setPoints(1);
  question1.setFeedbackForIncorrect(
    FormApp.createFeedback().setText("Incorrect. Please try again.").build());
  question1.setFeedbackForCorrect(
    FormApp.createFeedback().setText("Correct! Red,Green,Blue.").build());

  // Publish the form
  var formUrl = form.getPublishedUrl();
  Logger.log('Form URL: ' + formUrl);
}

Google's documentation uses setDisplayText while Apps Script would only accept setText, this has been already reported here.

huangapple
  • 本文由 发表于 2023年5月31日 23:44:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375246.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定