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

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

Currently you are comparing the index op against the answer key in column 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

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);  
}

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

Leave a Reply

Your email address will not be published.