✨ Introduction
Creating Google Forms manually for every quiz or survey can be tedious—especially when you’re working with multiple topics or classes. What if you could automate that process using JavaScript and generate quiz content using ChatGPT?
In this post, I’ll show you how I used ChatGPT to generate quiz questions and JavaScript to create a Google Form dynamically. You’ll also be able to download the exact script and prompt to create your own quiz forms in minutes.
🤖 What This Project Does
This JavaScript script automatically:
✅ Creates a Google Form titled “Header”
✅ Adds email and student name fields
✅ Adds 10 multiple-choice questions with auto-marking
✅ Gives positive feedback for each correct answer
✅ Logs the form’s edit URL in your script editor console
All of the content (questions and code) was generated using ChatGPT!
💬 Prompt Used in ChatGPT
Here’s the exact prompt I used to generate computer-based quiz questions:
Prompt:
“I’m giving you the JavaScript code to generate a Google Form. I want you to generate 10 questions based on the topic LibreOffice Calc. Replace the questions currently present in the code.”
ChatGPT then replaced the existing questions with accurate, educationally aligned Calc questions.
📄 JavaScript Code (Copy & Paste)
function myfunction() {
const form = FormApp.create("Header");
form.setDescription("This is a quiz on. Please enter your details and answer all questions.");
form.setCollectEmail(false); // We manually add an Email ID question
form.setIsQuiz(true);
// Add required fields
form.addTextItem()
.setTitle("Email ID")
.setRequired(true);
form.addTextItem()
.setTitle("Student Name")
.setRequired(true);
// Quiz questions
const questions = [
{
title: "What is the purpose of applying styles in a LibreOffice Writer document?",
choices: ["To check spelling", "To apply consistent formatting", "To insert tables", "To draw shapes"],
correct: 1
},
];
const itemFeedback = FormApp.createFeedback().setText("Great job!");
for (let q of questions) {
const item = form.addMultipleChoiceItem();
item.setTitle(q.title)
.setRequired(true);
.setPoints(1); // Assign 1 point to each question
const choices = q.choices.map((opt, idx) =>
item.createChoice(opt, idx === q.correct)
);
item.setChoices(choices);
const itemFeedback = FormApp.createFeedback()
.setText("Great job!")
.build();
item.setFeedbackForCorrect(itemFeedback);
}
Logger.log("Form created: " + form.getEditUrl());
}
🧠 Tips & Takeaways
You can modify this code to generate forms on any subject.
Just update the prompt to ChatGPT and ask for topic-specific questions.
Don’t forget to enable the Google Forms API in your Apps Script project settings.