How can I randomize the Answers(shuffle options order ) in the google forms programatically using google app script?.
There are methods available to set points, set required option in the forms but is there any methods available to shuffle answers.
My sample code as for now:-
var quest = SpreadsheetApp.getActiveSheet().getRange(1,4).getValue();
var ans1 = SpreadsheetApp.getActiveSheet().getRange(1,4).getValue();
var ans2 = SpreadsheetApp.getActiveSheet().getRange(1,5).getValue();
var ans3 = SpreadsheetApp.getActiveSheet().getRange(1,6).getValue();
var ans4 = SpreadsheetApp.getActiveSheet().getRange(1,9).getValue();
var item = form.addMultipleChoiceItem();
item.setChoices([
item.createChoice(ans1, false),
item.createChoice(ans2, false),
item.createChoice(ans3, false),
item.createChoice(ans4, true),
]);
item.setTitle(quest)
item.setRequired(true);
item.setPoints(1);
EDIT: IMPLEMENTED SOLUTION
I have implemented with below logic for my aforesaid question and it worked. I hope it may help others too. Below is the code snippet
var quest = SpreadsheetApp.getActiveSheet().getRange(2,3).getValue();
var ans1 = SpreadsheetApp.getActiveSheet().getRange(2,4).getValue();
var ans2 = SpreadsheetApp.getActiveSheet().getRange(2,5).getValue();
var ans3 = SpreadsheetApp.getActiveSheet().getRange(2,6).getValue();
var ans4 = SpreadsheetApp.getActiveSheet().getRange(2,7).getValue();
var correctans = SpreadsheetApp.getActiveSheet().getRange(2,8).getValue();
var item = form.addMultipleChoiceItem();
item.setTitle(quest);
if (ans1 == correctans){
item.setChoices([item.createChoice(ans1, true),item.createChoice(ans2,false),item.createChoice(ans3,false),item.createChoice(ans4,false)]);};
if (ans2 == correctans){
item.setChoices([item.createChoice(ans1, false),item.createChoice(ans2,true),item.createChoice(ans3,false),item.createChoice(ans4,false)]);};
if (ans3 == correctans){
item.setChoices([item.createChoice(ans1, false),item.createChoice(ans2,false),item.createChoice(ans3,true),item.createChoice(ans4,false)]);};
if (ans4 == correctans){
item.setChoices([item.createChoice(ans1, false),item.createChoice(ans2,false),item.createChoice(ans3,false),item.createChoice(ans4,true)]);};
item.setPoints(1);
item.setRequired(true);