0% found this document useful (0 votes)
48 views2 pages

Upload Form Code

This script creates a quiz form from data stored in a Google Sheet. It gets question and answer data from multiple ranges in the sheet. It then loops through each row, compares the answers to the possible choices, and dynamically builds a multiple choice question in the form with the correct answer selected. This allows quiz questions and answers to be managed in a spreadsheet and automatically generated into a Forms quiz.

Uploaded by

SMK Palapa Pare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views2 pages

Upload Form Code

This script creates a quiz form from data stored in a Google Sheet. It gets question and answer data from multiple ranges in the sheet. It then loops through each row, compares the answers to the possible choices, and dynamically builds a multiple choice question in the form with the correct answer selected. This allows quiz questions and answers to be managed in a spreadsheet and automatically generated into a Forms quiz.

Uploaded by

SMK Palapa Pare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

function OnerForm() {

var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheetByName('Sheet2');


var numberRows = sheet.getDataRange().getNumRows();
var myQuestions = sheet.getRange(1,1,numberRows,1).getValues();
var myAnswers = sheet.getRange(1,2,numberRows,1).getValues();
var myGuesses = sheet.getRange(1,2,numberRows,4).getValues();

Logger.log(myAnswers);

var form = FormApp.create('SOAL - SOAL');


form.setIsQuiz(true);
for(var i=0;i<numberRows;i++){
if (myGuesses[i][0] == myAnswers[i][0]) {
var addItem = form.addMultipleChoiceItem();
addItem.setTitle(myQuestions[i][0])
.setPoints(1)
.setChoices([

addItem.createChoice(myGuesses[i][0],true),

addItem.createChoice(myGuesses[i][1]),

addItem.createChoice(myGuesses[i][2]),

addItem.createChoice(myGuesses[i][3])

]);

else if (myGuesses[i][1] == myAnswers[i][0]) {

var addItem = form.addMultipleChoiceItem();

addItem.setTitle(myQuestions[i][0])

.setPoints(1)

.setChoices([

addItem.createChoice(myGuesses[i][0]),

addItem.createChoice(myGuesses[i][1],true),

addItem.createChoice(myGuesses[i][2]),

addItem.createChoice(myGuesses[i][3])

]);

else if (myGuesses[i][2] == myAnswers[i][0]) {

var addItem = form.addMultipleChoiceItem();


addItem.setTitle(myQuestions[i][0])

.setPoints(1)

.setChoices([

addItem.createChoice(myGuesses[i][0]),

addItem.createChoice(myGuesses[i][1]),

addItem.createChoice(myGuesses[i][2],true),

addItem.createChoice(myGuesses[i][3])

]);

else if (myGuesses[i][3] == myAnswers[i][0]) {

var addItem = form.addMultipleChoiceItem();

addItem.setTitle(myQuestions[i][0])

.setPoints(1)

.setChoices([

addItem.createChoice(myGuesses[i][0]),

addItem.createChoice(myGuesses[i][1]),

addItem.createChoice(myGuesses[i][2]),

addItem.createChoice(myGuesses[i][3],true)

]);

You might also like