Google Script Lesson 2 – Calling Functions

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.

Leave a comment

Your email address will not be published. Required fields are marked *