Teacher Tech blog with Alice Keeler

Paperless Is Not a Pedagogy

Alice Keeler

5 Basics to Know for Coding

5 coding basics for Google Apps Script
5 Basics to Know for Coding

Coding with Google Apps Script

As a G Suite user you may find yourself wishing… “Why can’t I …. in Google Docs/Sheets/Forms/Slides?” You can if you know how to code! Go to script.google.com to get started with standalone coding or in Docs, Sheets, or Slides use the Tools menu and choose “Script Editor.” This allows you to create code specifically for that document to make a template.

TemplateTab

TemplateTab is one of my favorite things I’ve coded. In a Google Sheets spreadsheet I used the Tools menu and the Script Editor to code the ability to take a list of student names and create a copy of a graphic organizer within the same spreadsheet for EACH student. A new tab for each student will be created, with their name on it, along the bottom. Share the spreadsheet with edit access with your students and have only ONE document to open rather than 30.

Alice Keeler Add-ons

You can find many of my coding projects at

5 Google Apps Script Basics

Google Apps Script is based on JavaScript. Knowing a little JavaScript will help you significantly in coding Google Apps Script.

1. Function

Each chunk of code is contained in a function. If your coding project has multiple steps you may want to set up multiple functions to allow for different features.

Notice in TemplateTab next to the Help menu is a menu I coded. The menu itself is one function; a set of code to tell the spreadsheet to have a menu. There are multiple options. The main option is to “Run TemplateTab.” That option is a separate function from the function to make the menu. Each menu item is a separate function I wrote.

TemplateTab menu

To create a function in Google Apps Script type the word function in all lower case. If you spelled it correctly it will turn purple. Put a space and then what you want to name your function. It has to be a single word. Notice for TemplateTab that I smooshed the words together to make one word. This is a common technique. Lowercase the first word, capitalize the first letter of any subsequent words.

menu of functions

This is a list of the function names I have for my TemplateTab script. Notice they are all one word.

After deciding on your function name, put a set of parenthesis to contain your parameters. Almost always you have no parameters so your parenthesis are blank. Then you need a set of curly braces to indicate the start and end of the function.

function templateTab(){
}

2. Variables

Variables store values so you can reuse values or code without having to retype the same thing you had already typed.

Define a variable by starting with the 3 letters var and then a space and what you want to name your variable (single word) and then an equals sign.

Want More Help with This? Become a Premium Member

3. Semi-Colon

Each line of code needs to end in a semi-colon to tell the script… this is the end of the line of code! This is where coding gets “fun.” You will forget a semi-colon at the end of a line and then your code won’t run and you have to figure out where you forgot the semi-colon.

Add a semi colon after the line of code

4. Spaces

Extra spaces and extra returns do not affect your code. Space out your code so it’s easier to view and read. Push enter several times to separate out different parts of your code.

Use two slashes // to create a COMMENT. This is like a post it note in your code. Consider pushing enter several times and typing 2 slashes to make a comment about what code is coming next.

Press enter several times and use 2 slashes to comment what comes next in your code.

5. GOOGLE IT!

One of the best things of living in the 21st century is that when you don’t know something you can “Google it.” If you want to code a date into your Google Apps document do a Google search for JavaScript date. Whatever you want to be able to do you can probably use the search terms “Google Apps Script” and what you’re looking for or “JavaScript” and what you’re looking for. Copy and paste code off the internet! You only need the idea and some perseverance to FIND the code that does what you want.

© 2024 All Rights Reserved.

💥 FREE OTIS WORKSHOP

Join Alice Keeler, Thursday Mar 28th or register to gain access to the recording.
Create a free OTIS account.

Join Alice Keeler for this session for a way to create dynamic and interactive digital lessons. The Desmos platform is completely free and allows for any topic to be created or customized.

Exit this pop up by pressing escape or clicking anywhere off the pop up.