How might we help educators to create Google Forms using Apps Script

by X | @rali2100 - Linkedin|R Ali

Created: 2023-12-08

Process 

Alternatively, use your own questions and answers. 


Prompt

Rewrite the above questions and answers into a Google Apps script code that will be added to an existing Google form. 

the form ID is XYZ

Use the following example to create the Apps script code:

Example of Apps Script Code 

This code format will help to create COPD questions on the form ID XYZ.  

In this example, there is one question. You can include more questions. 


function myFunction() {

// Get the form using the form ID

var form = FormApp.openById('XYZ');


// Add new section

var section1 = form.addSectionHeaderItem();

section1.setTitle('COPD Case');

// Add description

var description = 'Chronic obstructive pulmonary disease (COPD) is a group of lung conditions that cause breathing difficulties. It includes emphysema – damage to the air sacs in the lungs, and chronic bronchitis – long-term inflammation of the airways. COPD is a common condition that mainly affects middle-aged or older adults who smoke. Case: John, a 45-year-old man, has been smoking for the past 20 years. Recently, he has been experiencing shortness of breath, particularly when he\'s active, and a persistent chesty cough with phlegm. He also has frequent chest infections and persistent wheezing.';

section1.setHelpText(description);


// Add multiple choice question with true and false setting

var mcQuestion = form.addMultipleChoiceItem();

mcQuestion.setTitle("John's symptoms could be indicative of COPD. True or False?");

mcQuestion.setPoints(1);

mcQuestion.setChoices([

  mcQuestion.createChoice('True', true),

  mcQuestion.createChoice('False', false)

]);


// Add new section for answer

var section2 = form.addSectionHeaderItem();

section2.setTitle('Answer');


// Add answer with explanation

var answer = ' The correct answer is True. John\'s symptoms such as shortness of breath, particularly when active, a persistent chesty cough with phlegm, frequent chest infections, and persistent wheezing are common symptoms of COPD. Additionally, his history of long-term smoking is a major risk factor for the development of COPD. It\'s recommended that John seek medical advice for his persistent symptoms, particularly given his history of smoking.';

section2.setHelpText(answer);

}