{"id":16,"date":"2025-09-12T01:25:05","date_gmt":"2025-09-12T01:25:05","guid":{"rendered":"https:\/\/huongdan.anhtuanlqd.com\/?p=16"},"modified":"2025-09-27T15:04:22","modified_gmt":"2025-09-27T15:04:22","slug":"gdoc-to-gform-de-lam-mcqs","status":"publish","type":"post","link":"https:\/\/hd.follbc.org\/?p=16","title":{"rendered":"Gdoc to Gform \u0111\u1ec3 l\u00e0m MCQs"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">T\u1ea1o 1 file Gdocs v\u00e0 1 file Gform tr\u00ean google drive.<\/h2>\n\n\n\n<p>L\u1ea5y <strong>docId<\/strong> v\u00e0 <strong>formId<\/strong> trong link c\u1ee7a gdocs v\u00e0 gform. V\u00ed d\u1ee5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:\/\/docs.google.com\/document\/d\/<strong>1QYZ2KUOt-GOAARtoIUdvfcQ42ONag8hNMTkGlSYVKAc<\/strong>\/edit?tab=t.0\n\nhttps:\/\/docs.google.com\/forms\/d\/<strong>15JCx1nEIHWNKK2ZHikEHsbBsYeT2wT6yUb8PYQKEet0<\/strong>\/edit#settings<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">T\u1ea1o file Gdocs nh\u01b0 h\u00ecnh, th\u00ec tr\u00ean \u0111\u1ecba ch\u1ec9 s\u1ebd l\u1ea5y \u0111\u01b0\u1ee3c docid<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\nV\u00e0o Gform, v\u00e0o setting ch\u1ecdn \"Make this a quiz\"<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"587\" src=\"https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.57.47-1024x587.png\" alt=\"\" class=\"wp-image-30\" srcset=\"https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.57.47-1024x587.png 1024w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.57.47-300x172.png 300w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.57.47-768x440.png 768w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.57.47-1536x880.png 1536w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.57.47-2048x1174.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u1ea4n v\u00e0o ba ch\u1ea5m b\u00ean ph\u1ea3i tr\u00ean c\u00f9ng, ch\u1ecdn &#8220;Apps Script&#8221;<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"638\" src=\"https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.58.15-1024x638.png\" alt=\"\" class=\"wp-image-31\" srcset=\"https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.58.15-1024x638.png 1024w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.58.15-300x187.png 300w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.58.15-768x478.png 768w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.58.15-1536x957.png 1536w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-21.58.15-2048x1276.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Copy, paste code sau v\u00e0o:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * Imports questions from a Google Doc to a Google Form\n * Questions start with \"**\"\n * Answers start with \"##\" (first answer is correct by default)\n * If an answer starts with \"#!\", it overrides the default and becomes the correct answer\n *\/\nfunction importQuestionsFromDocToForm() {\n  \/\/ Replace with your actual document ID\n  const docId = \"<strong>1WBNi1JD-HDX0Y2-eVXjKSQN8OQCUUYgABRbc1QaTlyy<\/strong>\";\n  \/\/ Replace with your actual form ID, or create a new form\n  const formId = \"<strong>16QRO5t_xENLISRphGjwEsT3g-_Dd_CS7SG4FI676fVV<\/strong>\"; \n  \n  \/\/ Get the document and its content\n  const doc = DocumentApp.openById(docId);\n  const body = doc.getBody();\n  const text = body.getText();\n  \n  \/\/ Create or open the form\n  let form;\n  try {\n    form = FormApp.openById(formId);\n  } catch (e) {\n    \/\/ Create a new form if the ID doesn't exist\n    form = FormApp.create(\"Questions Form\");\n    console.log(\"Created new form with ID: \" + form.getId());\n  }\n  \n  \/\/ Split the text by \"**\" to get all questions\n  const sections = text.split(\"**\");\n  \n  \/\/ Skip the first element as it's before the first \"**\"\n  for (let i = 1; i &lt; sections.length; i++) {\n    const section = sections&#91;i].trim();\n    \n    \/\/ Skip empty sections\n    if (!section) continue;\n    \n    \/\/ Find where the question ends and answers begin\n    const firstAnswerIndex = section.indexOf(\"##\");\n    \n    \/\/ Skip if there are no answers\n    if (firstAnswerIndex === -1) continue;\n    \n    \/\/ Extract the question text\n    const questionText = section.substring(0, firstAnswerIndex).trim();\n    \n    \/\/ Skip if question is empty\n    if (!questionText) continue;\n    \n    \/\/ Get the answers part\n    const answersText = section.substring(firstAnswerIndex);\n    \n    \/\/ Split by \"##\" or \"#!\" to get all answers\n    const answerParts = answersText.split(\/(##|#!)\/);\n    \n    \/\/ Filter out the separators and empty parts\n    const answers = &#91;];\n    let correctAnswerIndex = 0; \/\/ Default: first answer is correct\n    \n    for (let j = 1; j &lt; answerParts.length; j += 2) {\n      const separator = answerParts&#91;j];\n      const answerText = (answerParts&#91;j + 1] || \"\").trim();\n      \n      if (answerText) {\n        answers.push(answerText);\n        \n        \/\/ If this answer starts with \"#!\", mark it as the correct one\n        if (separator === \"#!\") {\n          correctAnswerIndex = answers.length - 1;\n        }\n      }\n    }\n    \n    \/\/ Skip if no valid answers\n    if (answers.length === 0) continue;\n    \n    \/\/ Shuffle the answers and keep track of the correct answer\n    const shuffledAnswers = &#91;...answers];\n    const originalCorrectAnswer = answers&#91;correctAnswerIndex];\n    \n    \/\/ Fisher-Yates shuffle algorithm\n    for (let i = shuffledAnswers.length - 1; i &gt; 0; i--) {\n      const j = Math.floor(Math.random() * (i + 1));\n      &#91;shuffledAnswers&#91;i], shuffledAnswers&#91;j]] = &#91;shuffledAnswers&#91;j], shuffledAnswers&#91;i]];\n    }\n    \n    \/\/ Find the new index of the correct answer\n    const newCorrectAnswerIndex = shuffledAnswers.indexOf(originalCorrectAnswer);\n    \n    \/\/ Create a multiple choice question\n    const item = form.addMultipleChoiceItem();\n    item.setTitle(questionText);\n    \n    \/\/ Add all answers using the shuffled array\n    const choices = shuffledAnswers.map(answer =&gt; \n      item.createChoice(answer, shuffledAnswers.indexOf(answer) === newCorrectAnswerIndex)\n    );\n    item.setChoices(choices);\n\n    \/\/Set points for the question\n    item.setPoints(1);\n  }\n  \n  console.log(\"Import completed. Processed \" + (sections.length - 1) + \" question sections.\");\n}\n\n\/**\n * Creates a menu item to run the import function\n *\/\nfunction onOpen() {\n  const ui = DocumentApp.getUi();\n  ui.createMenu('Import to Form')\n    .addItem('Import Questions', 'importQuestionsFromDocToForm')\n    .addToUi();\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">S\u1ebd nh\u01b0 d\u01b0\u1edbi \u0111\u00e2y:<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"605\" src=\"https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-22.03.12-1024x605.png\" alt=\"\" class=\"wp-image-32\" srcset=\"https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-22.03.12-1024x605.png 1024w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-22.03.12-300x177.png 300w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-22.03.12-768x454.png 768w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-22.03.12-1536x908.png 1536w, https:\/\/hd.follbc.org\/wp-content\/uploads\/2025\/09\/Screenshot-2025-09-27-at-22.03.12-2048x1210.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Sau \u0111\u00f3, thay <strong>docId<\/strong> v\u00e0 <strong>formId <\/strong>l\u1ea5y \u0111\u01b0\u1ee3c t\u1eeb b\u01b0\u1edbc \u0111\u1ea7u ti\u00ean v\u00e0o trong code (\u0111\u00e3 b\u00f4i \u0111\u1eadm v\u1ecb tr\u00ed trong code). Sau \u0111\u00f3 save code v\u00e0 ch\u1ea1y, l\u00e0 form quiz s\u1ebd \u0111\u01b0\u1ee3c t\u1ea1o ra. Nh\u1edb c\u1ea5p permission n\u1ebfu \u0111\u01b0\u1ee3c h\u1ecfi.<\/p>\n\n\n\n<p>Y\u00eau c\u1ea7u format Gdoc nh\u01b0 test bank:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>**  Which of the following is a business financial decision?\n## Launching a new product\n## Choosing a holiday destination\n## Buying shares for retirement\n## Choosing between an annuity and a lump sum\n\n**  What is the core concept of finance?\n## Financial decision-making based on quantifiable dollar values\n## Making daily life decisions\n## Applying ethics to money\n## Negotiating salaries\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>T\u1ea1o 1 file Gdocs v\u00e0 1 file Gform tr\u00ean google drive. L\u1ea5y docId v\u00e0 formId [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-guide"],"_links":{"self":[{"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16"}],"version-history":[{"count":2,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":33,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions\/33"}],"wp:attachment":[{"href":"https:\/\/hd.follbc.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}