Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var form = FormApp.getActiveForm(); // Get the open form and make it a usable var for below
- var formTitle = form.getTitle();
- var document = DocumentApp.create(formTitle); // create a new Document called FormQuiz_conversion
- var question_position = 0; // variables for putting the questions and answers in the right position
- var answers_position = 0;
- var questions = form.getItems();
- var body = document.getBody();
- function convertActiveForm2Txt() // main function to run
- {
- for(var j = 0; j < questions.length; j++) // this loop is to label the titles with list numbers
- {
- write2doc(questions[j],j);
- }
- var bodyContents = body.getText();
- DriveApp.createFile(formTitle+"--import2Respondus.txt", bodyContents ,MimeType.PLAIN_TEXT);
- }
- function write2doc(quarshtun,j) // Iterate this function over all questions in the form
- {
- if (quarshtun.getType() == FormApp.ItemType.MULTIPLE_CHOICE) // check if the question is multiple choice
- {
- var question = quarshtun.asMultipleChoiceItem(); // change the type from Item to MultipleChoiceItem
- var choices = question.getChoices();
- var title = question.getTitle();
- var i = 0;
- body.appendParagraph(j+1+". "+title); // set the title of the question in the document
- for (i; i < choices.length; i++)
- {
- if(choices[i].isCorrectAnswer())
- {
- body.appendParagraph("\t"+"*"+String.fromCharCode(i+97)+". "+choices[i].getValue()); // if the choice is correct append it and * <--
- answers_position++;
- }
- else
- {
- body.appendParagraph("\t"+String.fromCharCode(i+97)+". "+choices[i].getValue()); // if else append it<--
- answers_position++;
- }
- }
- question_position += i;
- answers_position++;
- }
- question_position++;
- body.appendParagraph("\n"); // return break to the next question.
- }
Add Comment
Please, Sign In to add comment