0% found this document useful (0 votes)
57 views3 pages

Script Soal Google Form

This script creates a Google Form quiz from question and answer data stored in a Google Sheet. It gets the questions, answers, and shuffled multiple choice options from ranges in the sheet. It then loops through each row, creates a multiple choice question in the form with the correct answer marked, and adds it to the form. The rows are shuffled to randomize the answer order for each question.

Uploaded by

Wanda Winata
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)
57 views3 pages

Script Soal Google Form

This script creates a Google Form quiz from question and answer data stored in a Google Sheet. It gets the questions, answers, and shuffled multiple choice options from ranges in the sheet. It then loops through each row, creates a multiple choice question in the form with the correct answer marked, and adds it to the form. The rows are shuffled to randomize the answer order for each question.

Uploaded by

Wanda Winata
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
You are on page 1/ 3

function popForm() {

var ss = SpreadsheetApp.getActive();

var sheet = ss.getSheetByName('Sheet1');

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

var myShuffled = myGuesses.map(shuffleEachRow);

Logger.log(myShuffled);

Logger.log(myAnswers);

var form = FormApp.create('soal UAS Google Form');

form.setIsQuiz(true);

for(var i=0;i<numberRows;i++){

if (myShuffled[i][0] == myAnswers[i][0]) {

var addItem = form.addMultipleChoiceItem();

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

.setPoints(1)

.setChoices([

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

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

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

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

]);

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

var addItem = form.addMultipleChoiceItem();

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

.setChoices([

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

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

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

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

]);

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

var addItem = form.addMultipleChoiceItem();

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

.setPoints(1)

.setChoices([

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

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

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

addItem.createChoice(myShuffled[i][3]),

]);

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

var addItem = form.addMultipleChoiceItem();

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

.setPoints(1)

.setChoices([

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

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

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

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

]);
}

function shuffleEachRow(array) {

var i, j, temp;

for (i = array.length - 1; i > 0; i--) {

j = Math.floor(Math.random() * (i + 1));

temp = array[i];

array[i] = array[j];

array[j] = temp;

return array;

You might also like