在Google测验表单之间复制项目.getFeedbackForCorrect

时间:2017-05-21 07:57:56

标签: google-apps-script google-form google-classroom google-form-quiz

.duplicate()方法在表单之间不起作用(不是我所见),所以我编写了一个快速例程,将多项选择项从一个表单复制到另一个表单。

(我这样做是为了在Classroom中设置测验。我在形成性评估的测验中有一系列关于单一主题的问题,并希望将这些问题的随机问题结合起来进行总结性评估。)

我写的代码可以很好地复制问题而不是反馈。这是我的第一个GAS代码,所以道歉!

  

TypeError:在对象getFeedbackForCorrect中找不到函数Item。 (第32行,文件“代码”)

function copyMultipleChoiceItem(item1, item2) {
//  copies MC question item1 to item2 - tested PDW 17/05/20
//  copy of feedback not working
//
//  basic question items
    item2.setTitle(item1.getTitle());
    item2.setPoints(item1.asMultipleChoiceItem().getPoints());
    item2.setRequired(item1.asMultipleChoiceItem().isRequired());
    item2.setHelpText(item1.getHelpText());
//  the choices
    var choices = item1.asMultipleChoiceItem().getChoices();
    for (var i = 0; i < choices.length; i++) {
        item2.createChoice(choices[i].getValue(),choices[i].isCorrectAnswer());
    }
    item2.setChoices(choices);
//  the feedback and links - cannot get this to work!
    var feedback1 = item1.getFeedbackForCorrect();
    var feedback2 = FormApp.createFeedback()
        .setDisplayText(feedback1.getText());
//  then do list of URLs
    item2.setFeedbackForCorrect(feedback2);
}

1 个答案:

答案 0 :(得分:1)

您需要将item1作为多项选择。 getFeedbackForCorrect上没有item方法。您可以为项目创建一个新变量作为多项选择。

var itemAsMultipleChoice;

itemAsMultipleChoice = item1.asMultipleChoiceItem();//Get item as multiple choice item

然后使用新的itemAsMultipleChoice变量;

var feedback1 = itemAsMultipleChoice.getFeedbackForCorrect();

以下是整个功能:

function copyMultipleChoiceItem(item1, item2) {
//  copies MC question item1 to item2 - tested PDW 17/05/20
//  copy of feedback not working
//
//  basic question items
    var itemAsMultipleChoice;

    Logger.log('item1: ' + item1)

    itemAsMultipleChoice = item1.asMultipleChoiceItem();

    item2.setTitle(item1.getTitle());
    item2.setPoints(item1.asMultipleChoiceItem().getPoints());
    item2.setRequired(item1.asMultipleChoiceItem().isRequired());
    item2.setHelpText(item1.getHelpText());
//  the choices

    var choices = item1.asMultipleChoiceItem().getChoices();
    for (var i = 0; i < choices.length; i++) {
        item2.createChoice(choices[i].getValue(),choices[i].isCorrectAnswer());
    }
    item2.setChoices(choices);

    var feedback1 = itemAsMultipleChoice.getFeedbackForCorrect();

    var feedback2 = FormApp.createFeedback()
        .setDisplayText(feedback1.getText());
//  then do list of URLs
    item2.setFeedbackForCorrect(feedback2);
}