Last active
January 25, 2018 09:28
-
-
Save cyrusn/2fc39e982097a5e84ae1b35b43d8bc24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var form = FormApp.openByUrl("paste_the_link_of_the_form_here") | |
var students = [{"classcode":"1A","classno":1,"name":"Apple"}, | |
{"classcode":"1A","classno":2,"name":"Ball"}, | |
{"classcode":"1A","classno":3,"name":"Cat"}, | |
{"classcode":"1A","classno":4,"name":"Dog"}, | |
{"classcode":"1A","classno":5,"name":"Egg"}, | |
{"classcode":"1A","classno":6,"name":"Fan"}, | |
{"classcode":"1A","classno":7,"name":"Goat"}, | |
{"classcode":"1A","classno":8,"name":"Hand"}, | |
{"classcode":"1A","classno":9,"name":"Indian"}, | |
{"classcode":"1A","classno":10,"name":"Jam"}, | |
{"classcode":"1A","classno":11,"name":"King"}, | |
{"classcode":"1A","classno":12,"name":"Lamp"}, | |
{"classcode":"1A","classno":13,"name":"Man"}, | |
{"classcode":"1A","classno":14,"name":"Nurse"}, | |
{"classcode":"1A","classno":15,"name":"Owl"}, | |
{"classcode":"1A","classno":16,"name":"Pizza"}, | |
{"classcode":"1A","classno":17,"name":"Queen"}, | |
{"classcode":"1A","classno":18,"name":"Rail"}, | |
{"classcode":"1A","classno":19,"name":"Sun"}, | |
{"classcode":"1A","classno":20,"name":"Tiger"}, | |
{"classcode":"1A","classno":21,"name":"Umbrella"}, | |
{"classcode":"1A","classno":22,"name":"Vase"}, | |
{"classcode":"1A","classno":23,"name":"Woman"}, | |
{"classcode":"1A","classno":24,"name":"Box"}, | |
{"classcode":"1A","classno":25,"name":"Yard"}, | |
{"classcode":"1A","classno":26,"name":"Zoo"}] | |
function printTitle() { | |
var title = form.getTitle() // get the title of the form | |
Logger.log(title) // print the title in logger | |
} | |
function cleanup() { | |
form.getItems().forEach(function(item) { | |
form.deleteItem(item) | |
}) | |
} | |
function addStudentList() { | |
// map method change the content in the students array | |
// from {"classcode":"1A","classno":1,"name":"Apple"} to "1A - 1 - Apple" | |
var list = students.map(function(obj){ | |
return obj.classcode + "(" + obj.classno + ") - " + obj.name | |
}) | |
form.addListItem() | |
.setTitle("Please select your name") // set title of the question | |
.setRequired(true) // become a required question | |
.setChoiceValues(list) // set the list to choose | |
} | |
function askCourseInfo() { | |
// loop the contents 5 times | |
for (i = 0 ; i < 5 ; i++) { | |
// add section header for each question | |
form.addSectionHeaderItem().setTitle("Course " + (i + 1)) | |
// 1 line text input | |
form.addTextItem().setTitle("Course ID") | |
// multiple line text input | |
form.addParagraphTextItem().setTitle("Course Information") | |
} | |
} | |
function fullRun() { | |
cleanup() | |
form.setTitle("Mock Interview Application") // set title of the form | |
addStudentList() | |
askCourseInfo() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment