Claude를 활용한 구글 앱스크립트로 구글 설문지 퀴즈와 구글 문서 퀴즈 생성하기

소개

어제 구글 설문지 자동화가 너무 신나서

우리대학에 계시는 창의융복합 교수님들에게 설명하기 위해 다시 연습을 해봤습니다.

이번에는 구글 설문지와 구글 문서에 퀴즈 자동화를 했어요.

먼저 ChatGPT했으나 잘 안 됩니다.

클로드가 앱스크립트 잘 만들어줘요 ^^

프롬프트명령어 : 너는 구글 설문지를 만드는 전문가야. 너가 과일 단어를 영어 퀴즈로 만들려고 해 질문을 사지선다형 문제로 만들려고 해 그리고 이것을 구글 설문지로 만들어서 URL 링크를 생성해 주는 앱스크립트를 생성해줘

function createFruitVocabQuiz() {
  // Create a new form
  var form = FormApp.create('Fruit Vocabulary Quiz');
  
  // Configure form settings
  form.setDescription('Test your knowledge of fruit vocabulary in English!')
    .setIsQuiz(true)
    .setCollectEmail(true);
  
  // Quiz questions data structure
  var questions = [
    {
      question: 'What is the red fruit that doctors recommend to eat one a day?',
      options: ['Apple', 'Strawberry', 'Cherry', 'Tomato'],
      correct: 'Apple'
    },
    {
      question: 'Which yellow fruit is known for being rich in potassium?',
      options: ['Lemon', 'Banana', 'Pineapple', 'Mango'],
      correct: 'Banana'
    },
    {
      question: 'What is the large green fruit with pink flesh and black seeds?',
      options: ['Kiwi', 'Avocado', 'Watermelon', 'Honeydew'],
      correct: 'Watermelon'
    },
    {
      question: 'Which citrus fruit is orange in color?',
      options: ['Grapefruit', 'Lemon', 'Orange', 'Lime'],
      correct: 'Orange'
    },
    {
      question: 'What is the small, round purple fruit that grows in bunches?',
      options: ['Blueberry', 'Grape', 'Plum', 'Blackberry'],
      correct: 'Grape'
    }
  ];
  
  // Add questions to form
  questions.forEach(function(q) {
    var item = form.addMultipleChoiceItem();
    item.setTitle(q.question)
        .setPoints(1)
        .setChoices(q.options.map(function(option) {
          return item.createChoice(option, option === q.correct);
        }));
    
    // Add feedback for correct answer
    item.setFeedbackForCorrect(
      FormApp.createFeedback()
        .setText('Correct! Well done!')
        .build()
    );
    
    // Add feedback for incorrect answer
    item.setFeedbackForIncorrect(
      FormApp.createFeedback()
        .setText('Incorrect. The correct answer is: ' + q.correct)
        .build()
    );
  });
  
  // Get the form URL
  var formUrl = form.getPublishedUrl();
  
  // Create a trigger to send email when form is submitted
  ScriptApp.newTrigger('onFormSubmit')
    .forForm(form)
    .onFormSubmit()
    .create();
  
  // Log the URL
  Logger.log('Quiz form URL: ' + formUrl);
  return formUrl;
}

// Handle form submission
function onFormSubmit(e) {
  var response = e.response;
  var email = response.getRespondentEmail();
  var score = response.getGradableResponseForItem();
  
  // You can add email notification logic here if needed
}

https://docs.google.com/forms/d/1AkyPWu50VaWd10mgGhJSiZHSlI_t6rL7UvjLHNy2Mi8/edit

이 Apps Script 코드를 사용하는 방법을 설명해드리겠습니다:

  1. Google Apps Script에서 새 프로젝트를 만듭니다.

  2. 위의 코드를 복사하여 붙여넣기 합니다.

  3. 저장 버튼을 클릭합니다.

  4. createFruitVocabQuiz() 함수를 실행하면 자동으로:

    • 과일 관련 5개의 퀴즈 문제가 생성됩니다

    • 각 문제는 4개의 선택지가 있습니다

    • 정답과 오답에 대한 피드백이 포함됩니다

    • 퀴즈 점수가 자동으로 계산됩니다

이 퀴즈는 다음과 같은 특징이 있습니다:

  • 이메일 수집 기능

  • 자동 채점 기능

  • 즉각적인 피드백 제공

  • 각 문제당 1점씩 배점

코드를 수정하여 다음과 같은 사항을 변경할 수 있습니다:

  • 문제와 보기 내용

  • 점수 배점

  • 피드백 메시지

  • 퀴즈 제목과 설명

추가 기능이나 다른 종류의 문제를 원하시나요?

아래는 구글 문서로 만들어 달라고 지시한 것입니다.

function createFruitVocabQuizDoc() {
  // Create a new Google Doc
  var doc = DocumentApp.create('Fruit Vocabulary Quiz');
  var body = doc.getBody();
  
  // Add title and instructions
  body.appendParagraph('Fruit Vocabulary Quiz')
      .setHeading(DocumentApp.ParagraphHeading.HEADING1)
      .setAlignment(DocumentApp.HorizontalAlignment.CENTER);
      
  body.appendParagraph('Instructions: Circle the correct answer for each question.')
      .setHeading(DocumentApp.ParagraphHeading.NORMAL)
      .setAlignment(DocumentApp.HorizontalAlignment.LEFT);
  
  body.appendParagraph('\n'); // Add blank line
  
  // Quiz questions
  var questions = [
    {
      number: 1,
      question: 'What is the red fruit that doctors recommend to eat one a day?',
      options: ['Apple', 'Strawberry', 'Cherry', 'Tomato'],
      correct: 'Apple'
    },
    {
      number: 2,
      question: 'Which yellow fruit is known for being rich in potassium?',
      options: ['Lemon', 'Banana', 'Pineapple', 'Mango'],
      correct: 'Banana'
    },
    {
      number: 3,
      question: 'What is the large green fruit with pink flesh and black seeds?',
      options: ['Kiwi', 'Avocado', 'Watermelon', 'Honeydew'],
      correct: 'Watermelon'
    },
    {
      number: 4,
      question: 'Which citrus fruit is orange in color?',
      options: ['Grapefruit', 'Lemon', 'Orange', 'Lime'],
      correct: 'Orange'
    },
    {
      number: 5,
      question: 'What is the small, round purple fruit that grows in bunches?',
      options: ['Blueberry', 'Grape', 'Plum', 'Blackberry'],
      correct: 'Grape'
    }
  ];
  
  // Add questions to document
  questions.forEach(function(q) {
    // Add question
    body.appendParagraph(q.number + '. ' + q.question)
        .setHeading(DocumentApp.ParagraphHeading.NORMAL);
    
    // Add options
    q.options.forEach(function(option, index) {
      body.appendParagraph('   ' + String.fromCharCode(97 + index) + ') ' + option)
          .setHeading(DocumentApp.ParagraphHeading.NORMAL);
    });
    
    body.appendParagraph('\n'); // Add blank line between questions
  });
  
  // Add answer key at the end
  body.appendPageBreak();
  body.appendParagraph('Answer Key')
      .setHeading(DocumentApp.ParagraphHeading.HEADING2);
      
  questions.forEach(function(q) {
    body.appendParagraph(q.number + '. ' + q.correct)
        .setHeading(DocumentApp.ParagraphHeading.NORMAL);
  });
  
  // Get the document URL
  var docUrl = doc.getUrl();
  
  // Log the URL
  Logger.log('Quiz document URL: ' + docUrl);
  return docUrl;
}

https://docs.google.com/document/d/1ase8H_qkltzJ618sPWF0r_TN5FEZpZPeNtx_fudkNyE/edit?tab=t.0

진행 방법

Claude 가 아래와 같이 하도록 설명을 해줍니다.

이 Apps Script 코드를 사용하는 방법을 설명해드리겠습니다:

  1. Google Apps Script에서 새 프로젝트를 만듭니다.

  2. 위의 코드를 복사하여 붙여넣기 합니다.

  3. 저장 버튼을 클릭합니다.

  4. createFruitVocabQuiz() 함수를 실행하면 자동으로:

    • 과일 관련 5개의 퀴즈 문제가 생성됩니다

    • 각 문제는 4개의 선택지가 있습니다

    • 정답과 오답에 대한 피드백이 포함됩니다

    • 퀴즈 점수가 자동으로 계산됩니다

이 퀴즈는 다음과 같은 특징이 있습니다:

  • 이메일 수집 기능

  • 자동 채점 기능

  • 즉각적인 피드백 제공

  • 각 문제당 1점씩 배점

코드를 수정하여 다음과 같은 사항을 변경할 수 있습니다:

  • 문제와 보기 내용

  • 점수 배점

  • 피드백 메시지

  • 퀴즈 제목과 설명

추가 기능이나 다른 종류의 문제를 원하시나요?

한국어가 포함된 한국 웹사이트의 스크린샷

결과와 배운 점

‎​구글 앱스크립트는 챗지피티는 애러가 나고 클로드에서 잘 생성됩니다.

도움 받은 글 (옵션)

‎​(내용 입력)

1
2개의 답글

👉 이 게시글도 읽어보세요