Student Self-Grading Assignment Part 1

A student self-checking, self-grading assignment provides students with immediate feedback to encourage additional effort and accuracy. When the Google Slides Presentation is copied (through Google Classroom or Drive), the Apps Script attached to the presentation is copied along with it. This is a three part project. This part explains the script that will build an answer key table directly from the presentation.

Build an Answer Key Table Directly from the Assignment on Click.

  1. Open a new Google Slides presentation.
  2. Open the Script editor.
  3. Copy and paste the code into the Script editor.
  4. Save the script file
  5. Insert a 1 by 1 table onto the first slide
  6. Right-click the edge of the table to edit the alt text description of the table to ak
  7. Continue to Student Self-Checking Assignment Part 2

    /**
    * @OnlyCurrentDoc 
    */
   
   class Answer{
       constructor(index, text, left, top){
         this.index = index;
         this.text = text; 
         this.left = left;
         this.top = top;
       }
     }
   
   function buildKey() {
   
     var presentation = SlidesApp.getActivePresentation();
     var slides = presentation.getSlides();
     var aK = [];
   
     if (slides[0].getTables().length > 0) {
       for (let i = 0; i < slides[0].getTables().length; i++) {
         if (slides[0].getTables()[i].getDescription() == "ak") {
           var docKey = slides[0].getTables()[i];
           break;
         }
       }
     }
   
     if (docKey) {
   
       while (docKey.getNumRows() > 1) {
         docKey.getRow(0).remove();
       }
   
       while (docKey.getNumColumns() > 1) {
         docKey.getColumn(0).remove();
       }
   
       docKey.getCell(0, 0).getText().setText("");
   
       var itemNumber = 0;
       slides.forEach(function getBoxes(slide, index) {
         slideNumber = index;
         slide.getPageElements().forEach(function getContent(shape) {
           if (shape.getPageElementType() == SlidesApp.PageElementType.SHAPE) {
             if (shape.asShape().getTitle() == "response") {
               shape.asShape().setDescription(itemNumber);
               let answer = new Answer(itemNumber, shape.asShape().getText().asString().toLowerCase().replace(/ /g, "").trim().split(';').join(';'), 0, 0);
               aK.push(answer);
               itemNumber++;
             } else if (shape.asShape().getTitle() == "position") {
               shape.asShape().setDescription(itemNumber);
               let answer = new Answer(itemNumber, 0, parseInt(shape.asShape().getLeft()), parseInt(shape.asShape().getTop()));
               aK.push(answer);
               itemNumber++;
             }
           }
         });
       });
   
       while (docKey.getNumColumns() < 4) {
         docKey.appendColumn();
       }
   
       var count = 0;
       aK.forEach(function postKey(obj) {
         docKey.getCell(count, 0).getText().setText(obj.index);
         docKey.getCell(count, 1).getText().setText(obj.text);
         docKey.getCell(count, 2).getText().setText(obj.left);
         docKey.getCell(count, 3).getText().setText(obj.top);
         if (count < aK.length - 1) {
           docKey.appendRow();
         }
         count++;
       });
   
     } else {
       SlidesApp.getUi().alert("There is no answer key table on the first slide.");
     }
   }
Copyright © 2022 WhatEverItSaysIsFine privacy policyterms & conditions