In this challenge, we’ll take the principles from the previous example one step further. Here, in addition to simply defining functions, we are also CALLING a function: newFunction.
function myFunction() { newFunction(); }
function newFunction(){ }
Note here that the first function, myFunction, calls newFunction. You can tell that it CALLS newFunction because the first time newFunction appears in the program it does NOT have the word ‘function’ in front of it. Also, it is followed by a semicolon ; instead of braces {}.
This syntax is important, so memorize it now:
DEFINING a function – uses the word ‘function’, followed by () and {}
CALLING a function – does NOT use word ‘function, followed by () and ;
Either create a new Script file in your Drive folder, or click on this example and make a copy. To make a copy, click File > “Make a Copy…”
Challenge:
- Make the logger display three lines of text, whatever you want (extra points for a Haiku).
- Each Logger.log command has to be in its OWN function. That means that you will have to both DEFINE and CALL a third function, as well as add Logger.log commands to all three functions.
Google Scripts Lessons 1-10
Click on a lesson below for a written tutorial demonstrating the lesson.
- Lesson 1 – “Hello World!”
- Lesson 2 – Challenge: Calling Functions
- Lesson 3 – Variables
- Lesson 4 – Variable Passing
- Lesson 5 – Variable Passing Challenge
- Lesson 6 – Arrays of Variables
- Lesson 7 – Modifying a Google Doc
- Lesson 8 – Modify Doc and Send Email
- Lesson 9 – Simple Feedback script
- Lesson 10 – Full-scale feedback