1

I am wanting to set the value of a Answer Key to a specific quiz item using google app scripts. Looking through the docs, I could not find what I was looking for.

I can programmatically generate random questions, but need to now programmatically set the answer using a google forms- quiz.

function onOpen(e) {
  var form = FormApp.getActiveForm();
  var items = form.getItems();
  for (var i in items) { 
    Logger.log(items[i].getTitle() + ': ' + items[i].getId());
  }
  var force1 = 10 + (Math.round(Math.random()*10));
  var distance1 = 10 + (Math.round(Math.random()*10));
  items[1].setTitle(' (W1)  Given a force of ' + force1 + ', and a displacement of ' + distance1 + '.  What is the value of Work?');

  //Generate correct answer by quiz item variables
  //Set correct answer to quiz item 1

  //When the student clicks submit, the quiz is graded on the correct answers generated and set by the google app scripts.
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
  • 1
    Possible duplicate of [Using Google Apps Script to set the correct answer in a Google Forms (that has been defined as a quiz)](https://stackoverflow.com/questions/39603541/using-google-apps-script-to-set-the-correct-answer-in-a-google-forms-that-has-b) – P Burke Jan 16 '19 at 18:24

1 Answers1

-1

textItem validation and validationBuilder seem to be the things you need. Here is an example from the Apps script docs:

// Add a text item to a form and require it to be a number within a range.
var textItem = form.addTextItem().setTitle('Pick a number between 1 and 100?');
var textValidation = FormApp.createTextValidation()
  .setHelpText(“Input was not a number between 1 and 100.”)
  .requireNumberBetween(1, 100);
textItem.setValidation(textValidation);
Дмитро Булах
  • 3,697
  • 1
  • 14
  • 23