// Google Appscript โดย ผศ.ดร.กิตติพงษ์ สุวรรณราช (อ.โจ้)
// ช่อง Youtube : IT around U ฝากกดติดตามด้วยนะครับ
// กดติดตามที่ https://youtube.com/c/itaroundu?sub_confirmation=1
// วิทยากร AI and Google Certified Trainer
function createQuizForm() {
// สร้าง Form ใหม่
var form = FormApp.create('แบบทดสอบ Google Data Studio');
// ตั้งค่าให้เป็นแบบทดสอบ
form.setIsQuiz(true);
// กำหนดการตั้งค่าฟอร์ม
form.setDescription('แบบทดสอบเกี่ยวกับ Google Data Studio');
form.setCollectEmail(true);
form.setLimitOneResponsePerUser(true);
// ข้อมูลคำถามและคำตอบ
var questionsAndAnswers = [
{
question: "Google Data Studio คืออะไร?",
choices: ["โปรแกรมแก้ไขรูปภาพ", "เครื่องมือวิเคราะห์ข้อมูลและสร้างรายงานแบบ Realtime", "แพลตฟอร์มสำหรับเขียนโค้ด", "เครื่องมือสำหรับสร้างเว็บไซต์"],
answer: "เครื่องมือวิเคราะห์ข้อมูลและสร้างรายงานแบบ Realtime"
},
{
question: "การเชื่อมต่อข้อมูลจาก Google Analytics กับ Google Data Studio ต้องทำอย่างไร?",
choices: ["ใช้ API Key", "ใช้ OAuth 2.0", "ใช้ Username และ Password", "ใช้ Token"],
answer: "ใช้ OAuth 2.0"
}
];
// วนลูปเพื่อสร้างคำถามทั้งหมด
questionsAndAnswers.forEach(function(qa, index) {
// สร้างคำถามแบบหลายตัวเลือก
var item = form.addMultipleChoiceItem();
// กำหนดคำถามและตัวเลือก
item.setTitle(qa.question)
.setPoints(1) // กำหนดคะแนนเป็น 1 คะแนนต่อข้อ
.setChoices(qa.choices.map(function(choice) {
return item.createChoice(choice, choice === qa.answer);
}));
// กำหนดคำอธิบายสำหรับคำตอบที่ถูกต้อง
item.setFeedbackForCorrect(
FormApp.createFeedback()
.setText('ถูกต้อง! คำตอบคือ: ' + qa.answer)
.build()
);
// กำหนดคำอธิบายสำหรับคำตอบที่ผิด
item.setFeedbackForIncorrect(
FormApp.createFeedback()
.setText('ไม่ถูกต้อง คำตอบที่ถูกคือ: ' + qa.answer)
.build()
);
});
// ตั้งค่าการแสดงผลคะแนน
form.setPublishingSummary(true);
// แสดง URL ของฟอร์มที่สร้าง
Logger.log('Form URL: ' + form.getPublishedUrl());
Logger.log('Form Edit URL: ' + form.getEditUrl());
}
// ฟังก์ชันสำหรับเรียกใช้งาน
function runScript() {
createQuizForm();
}