Bird
Raised Fist0
Google Sheetsspreadsheet~20 mins

Script editor overview in Google Sheets - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Script Editor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main purpose of the Script Editor in Google Sheets?

The Script Editor in Google Sheets allows you to:

ASort and filter data within the spreadsheet
BChange the font and color of cells in the spreadsheet
CCreate charts and graphs from your data
DWrite and run custom scripts to automate tasks and add new features
Attempts:
2 left
💡 Hint

Think about what scripting means and how it can help with repetitive tasks.

📊 Formula Result
intermediate
2:00remaining
What will this simple script output in the Logger?

Consider this Google Apps Script code run from the Script Editor:

function logSum() {
  var a = 5;
  var b = 7;
  Logger.log(a + b);
}

What will appear in the Logs after running logSum()?

A12
B57
Ca + b
DError: Logger is undefined
Attempts:
2 left
💡 Hint

Logger.log prints the value of the expression inside the parentheses.

Function Choice
advanced
2:00remaining
Which function correctly gets the active spreadsheet in Google Sheets Script Editor?

You want to write a script that works on the currently open spreadsheet. Which function should you use?

ASpreadsheetApp.getActiveSpreadsheet()
BSpreadsheetApp.openById()
CSpreadsheetApp.getUi()
DSpreadsheetApp.create()
Attempts:
2 left
💡 Hint

Think about which function returns the spreadsheet you are currently working on.

🎯 Scenario
advanced
2:00remaining
You want to create a custom menu in Google Sheets using the Script Editor. Which method adds a new menu to the spreadsheet UI?

Which method should you use to add a custom menu to the Google Sheets interface?

ASpreadsheetApp.createMenu('My Menu').addItem('Say Hello', 'myFunction')
BSpreadsheetApp.getUi().createMenu('My Menu').addItem('Say Hello', 'myFunction').addToUi()
CSpreadsheetApp.getActiveSpreadsheet().addMenu('My Menu')
DSpreadsheetApp.getUi().addMenu('My Menu')
Attempts:
2 left
💡 Hint

Menus are part of the user interface, so you need to get the UI first.

data_analysis
expert
2:00remaining
What will be the value of cell A1 after running this script?

Given this script run from the Script Editor:

function writeValue() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.getRange('A1').setValue('Hello');
  sheet.getRange('A1').setValue(sheet.getRange('A1').getValue() + ' World');
}

What will cell A1 contain after writeValue() runs?

AWorld
BHello
CHello World
DError: Cannot concatenate values
Attempts:
2 left
💡 Hint

Look at how the script reads and updates the cell value step by step.

Practice

(1/5)
1. What is the main purpose of the Script Editor in Google Sheets?
easy
A. To import data from other spreadsheets only
B. To write JavaScript code to customize and automate tasks in the spreadsheet
C. To format cells with colors and fonts
D. To create charts and graphs automatically

Solution

  1. Step 1: Understand the Script Editor's role

    The Script Editor allows writing JavaScript code to customize Google Sheets.
  2. Step 2: Identify the main use

    It is mainly used to automate tasks and add custom features, not just formatting or charting.
  3. Final Answer:

    To write JavaScript code to customize and automate tasks in the spreadsheet -> Option B
  4. Quick Check:

    Script Editor = JavaScript customization [OK]
Hint: Script Editor = write code to automate sheets [OK]
Common Mistakes:
  • Thinking Script Editor is for formatting only
  • Confusing it with chart tools
  • Believing it only imports data
2. Which of the following is the correct way to start a function in Google Sheets Script Editor?
easy
A. function myFunction() { }
B. def myFunction() { }
C. func myFunction() { }
D. function: myFunction() { }

Solution

  1. Step 1: Recall JavaScript function syntax

    Google Sheets scripts use JavaScript, where functions start with the keyword 'function'.
  2. Step 2: Match the correct syntax

    Only 'function myFunction() { }' matches JavaScript syntax correctly.
  3. Final Answer:

    function myFunction() { } -> Option A
  4. Quick Check:

    JavaScript function syntax = function name() { } [OK]
Hint: JavaScript functions start with 'function' keyword [OK]
Common Mistakes:
  • Using Python or other language syntax
  • Adding colons after function keyword
  • Using incorrect keywords like 'def' or 'func'
3. Given this script in the Script Editor:
function showAlert() {
  SpreadsheetApp.getUi().alert('Hello!');
}

What happens when you run showAlert()?
medium
A. An error occurs because alert is not a valid method
B. The message 'Hello!' is printed in the console only
C. Nothing happens because the function is empty
D. A popup alert with the message 'Hello!' appears in the spreadsheet

Solution

  1. Step 1: Understand the function code

    The function calls SpreadsheetApp.getUi().alert('Hello!'), which shows a popup alert in the spreadsheet UI.
  2. Step 2: Identify the effect of running the function

    Running showAlert() triggers the alert popup with the message 'Hello!'.
  3. Final Answer:

    A popup alert with the message 'Hello!' appears in the spreadsheet -> Option D
  4. Quick Check:

    alert() shows popup message [OK]
Hint: alert() shows popup in spreadsheet UI [OK]
Common Mistakes:
  • Thinking alert prints to console
  • Assuming function does nothing
  • Believing alert method is invalid
4. You wrote this script in the Script Editor:
function addNumbers() {
  var sum = 5 + ;
  Logger.log(sum);
}

What is the error and how do you fix it?
medium
A. Syntax error due to incomplete addition; fix by adding a number after '+'
B. Runtime error because Logger.log is not defined; fix by importing Logger
C. No error; script runs and logs 5
D. Syntax error because 'var' is not allowed; fix by removing 'var'

Solution

  1. Step 1: Identify the syntax error in the addition

    The expression '5 + ;' is incomplete and causes a syntax error because a number is missing after '+'.
  2. Step 2: Fix the error by completing the addition

    Add a number after '+' like '5 + 3' to fix the syntax error.
  3. Final Answer:

    Syntax error due to incomplete addition; fix by adding a number after '+' -> Option A
  4. Quick Check:

    Incomplete expression causes syntax error [OK]
Hint: Check for missing operands in math expressions [OK]
Common Mistakes:
  • Thinking Logger.log causes error
  • Assuming 'var' is invalid
  • Ignoring incomplete expression
5. You want to create a custom menu in Google Sheets using the Script Editor that runs a function named processData. Which script snippet correctly adds this menu when the spreadsheet opens?
hard
A. function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Custom Menu') .addItem('Run Process') .addToUi(); }
B. function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Custom Menu') .addItem('Run Process', processData) .addToUi(); }
C. function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Custom Menu') .addItem('Run Process', 'processData') .addToUi(); }
D. function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Custom Menu') .addItem('Run Process', 'processData()') .addToUi(); }

Solution

  1. Step 1: Understand how to add a custom menu

    The method addItem requires two arguments: the menu label as a string and the function name as a string without parentheses.
  2. Step 2: Identify the correct syntax

    function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Custom Menu') .addItem('Run Process', 'processData') .addToUi(); } correctly passes 'processData' as a string and chains the calls properly.
  3. Final Answer:

    function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Custom Menu') .addItem('Run Process', 'processData') .addToUi(); } -> Option C
  4. Quick Check:

    addItem needs function name as string [OK]
Hint: Pass function name as string in addItem [OK]
Common Mistakes:
  • Passing function reference without quotes
  • Including parentheses in function name string
  • Omitting second argument in addItem