Skip to main content

How to Get the Quiz Score in Google Forms with Apps Script

Teachers can easily create an online quiz using Google Forms and students can view their test scores immediately after form submission.

Teachers can use Google Forms to create an online quiz and students can view their test scores immediately after form submission. With Apps Script, you can set up automatic email notifications and send quiz scores to parents after a student has taken the quiz.

Here’s a sample Google Script that will iterate through every answer in the most recent Google Form response and log the max score (points) of a gradable question and the score for the respondent’s submitted answer.

function getGoogleFormQuizScore() {

  // Returns the form to which the script is container-bound.
  var form = FormApp.getActiveForm();

  // Get the most recently submitted form response
  var response = form.getResponses().reverse()[0];

  // Gets an array of all items in the form.
  var items = form.getItems();

  for (var i=0; i<items.length; i++) {

    var question = items[i];

    // Get the item's title text
    var qTitle = question.getTitle();

    // Get the item's type like Checkbox, Multiple Choice, Grid, etc.
    var qType = question.getType();

    // Gets the item response contained in this form response for a given item.
    var responseForItem = response.getResponseForItem(question)

    //Gets the answer that the respondent submitted.
    var answer = responseForItem ? responseForItem.getResponse() : null;

    var item = castQuizItem_(question, qType);

    // Quiz Score and Maximum Points are not available
    // for Checkbox Grid and Multiple Choice Grid questions
    // through they are gradable in the Google Form

    if (item && typeof item.getPoints === "function") {

      var maxScore = item.getPoints();
      var gradableResponseForItem = response.getGradableResponseForItem(question);
      var score = gradableResponseForItem.getScore();

      Logger.log(String(qType), qTitle, answer, maxScore, score);

    }
  }
}

The Google Forms API can only return scores for Multiple Choice, Dropdown and Checkbox style questions. It cannot provide scores for the grid type of questions where the item is presented as a grid of rows and columns.

  1. Checkbox Grid - A question item that allows the respondent to select multiple choices per row from a sequence of checkboxes.
  2. Choice Grid - A question item that allows the respondent to select one choice per row from a sequence of radio buttons.
function castQuizItem_(item, itemType) {
  if (itemType === FormApp.ItemType.CHECKBOX) {
    return item.asCheckboxItem();
  }
  if (itemType === FormApp.ItemType.DATE) {
    return item.asDateItem();
  }
  if (itemType === FormApp.ItemType.DATETIME) {
    return item.asDateTimeItem();
  }
  if (itemType === FormApp.ItemType.DURATION) {
    return item.asDurationItem();
  }
  if (itemType === FormApp.ItemType.LIST) {
    return item.asListItem();
  }
  if (itemType === FormApp.ItemType.MULTIPLE_CHOICE) {
    return item.asMultipleChoiceItem();
  }
  if (itemType === FormApp.ItemType.PARAGRAPH_TEXT) {
    return item.asParagraphTextItem();
  }
  if (itemType === FormApp.ItemType.SCALE) {
    return item.asScaleItem();
  }
  if (itemType === FormApp.ItemType.TEXT) {
    return item.asTextItem();
  }
  if (itemType === FormApp.ItemType.TIME) {
    return item.asTimeItem();
  }
  if (itemType === FormApp.ItemType.GRID) {
    return item.asGridItem();
  }
  if (itemType === FormApp.ItemType.CHECKBOX_GRID) {
    return item.asCheckboxGridItem();
  }
  if (itemType === FormApp.ItemType.PAGE_BREAK) {
    return item.asPageBreakItem();
  }
  if (itemType === FormApp.ItemType.SECTION_HEADER) {
    return item.asSectionHeaderItem();
  }
  if (itemType === FormApp.ItemType.VIDEO) {
    return item.asVideoItem();
  }
  if (itemType === FormApp.ItemType.IMAGE) {
    return item.asImageItem();
  }
  return null;
}

Quiz in Google Forms with Score

Google Form Quiz

Comments

Popular posts from this blog

Let People Quickly Save your Events on their Calendars

Create Add to Calendar links for emails and websites and let users quickly save your events on their own Google Calendar, Outlook or Yahoo Calendar. You are organizing an online event - maybe a meeting on Zoom or a training session hosted on Google Meet - and you would like the attendees to add the event to their own calendars. Once added to their calendar, the event will act as an automatic reminder and attendees will get a notification when the conference is about to start. There are two way to go about this: You can create a new meeting in your online calendar (Google, Outlook or any other calendar) and add the individual attendees as guests so the event automatically gets added to their calendar as well. You can include an “Add to Calendar” link or button in your email messages,  forms  and website pages. Anyone can click the link to quickly save your event on to their calendars - see  live demo . Create Add to Calendar Links for Emails and Websites The  Add to C...

The Most Awesome Online Teachers for Learning Web Development

For the past few months, I have been on a learning spree looking to enhance my existing coding skills and also learn new programming languages and frameworks. In this process, I have watched a countless number of video tutorials and online courses that pertain to programming and, specifically, web development. In my quest to become a better developer, I’ve come across several awesome “teachers” who aren’t just excellent programmers but awesome educators and have the art of explaining complex and difficult concepts. Learn Modern Web Programming with the Best Online Teachers This is an attempt to highlight the best instructors on the Internet for JavaScript, React, Redux, Node.js, Firebase (database and storage), Docker, Google Golang, Typescript, Flutter (for mobile app development), Dart, Git, Webpack and Parcel bundler. I’ve taken courses by every single instructor mentioned here ( PDF ) and recommend them highly. Language / Platform Teacher / Course React.js Andrew...