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
Recall & Review
beginner
What is the purpose of the onEdit trigger in Google Sheets?
The onEdit trigger runs a script automatically whenever a user changes a cell in the spreadsheet. It helps automate tasks based on edits.
Click to reveal answer
beginner
When does the onOpen trigger run in Google Sheets?
The onOpen trigger runs a script automatically every time the spreadsheet is opened by a user. It is useful for setup tasks like creating menus.
Click to reveal answer
intermediate
Can onEdit triggers run if a script changes a cell value?
No, onEdit triggers only run when a user manually edits a cell, not when a script changes a cell value.
Click to reveal answer
beginner
How do you create a simple onEdit trigger function in Google Sheets?
You write a function named onEdit(e) in the script editor. Google Sheets automatically runs it when a cell is edited.
Click to reveal answer
beginner
What kind of tasks are good candidates for onOpen triggers?
Tasks like adding custom menus, showing welcome messages, or setting up initial spreadsheet states are good for onOpen triggers.
Click to reveal answer
Which trigger runs when you open a Google Sheet?
AonOpen
BonEdit
ConChange
DonLoad
✗ Incorrect
onOpen runs when the spreadsheet is opened.
What event causes the onEdit trigger to run?
AScript changes a cell
BSpreadsheet opens
CUser edits a cell
DSpreadsheet is saved
✗ Incorrect
onEdit runs only when a user manually edits a cell.
Can onEdit triggers detect changes made by scripts?
AYes, always
BOnly if script calls onEdit manually
COnly on weekends
DNo, only user edits
✗ Incorrect
onEdit triggers do not run for script-made changes.
What is the correct function name for an onOpen trigger?
AonOpen(e)
BonOpen()
CopenTrigger()
DonOpenTrigger()
✗ Incorrect
The function should be named onOpen(e) to receive the event object.
Which trigger is best to add a custom menu when the sheet opens?
AonEdit
BonOpen
ConChange
DonInstall
✗ Incorrect
onOpen is used to add menus when the sheet opens.
Explain how the onEdit trigger works in Google Sheets and give an example of when you might use it.
Think about what happens when you change a cell manually.
You got /3 concepts.
Describe the purpose of the onOpen trigger and how it can improve user experience in a spreadsheet.
Consider what you want users to see or have ready when they open the sheet.
You got /3 concepts.
Practice
(1/5)
1. What does the onOpen trigger do in Google Sheets?
easy
A. Saves the spreadsheet automatically
B. Runs a script automatically when the spreadsheet is opened
C. Runs a script when a cell is edited
D. Deletes all data when the sheet is opened
Solution
Step 1: Understand the purpose of onOpen
The onOpen trigger runs a script automatically when the spreadsheet is opened by a user.
Step 2: Compare with other triggers
Unlike onEdit, which runs on cell changes, onOpen activates only on opening the file.
Final Answer:
Runs a script automatically when the spreadsheet is opened -> Option B
Quick Check:
onOpen = runs on open [OK]
Hint: Remember: onOpen triggers when file opens, not on edits [OK]
Common Mistakes:
Confusing onOpen with onEdit trigger
Thinking onOpen runs on every cell change
Assuming onOpen saves the file automatically
2. Which of the following is the correct way to define an onEdit trigger function in Google Sheets Apps Script?
easy
A. function onEdit(e) { /* code here */ }
B. function onEdit { /* code here */ }
C. function onEdit() { /* code here */ }
D. function onEdit(e) => { /* code here */ }
Solution
Step 1: Recall correct function syntax with event object
The onEdit trigger function must accept an event object parameter e to access edit details.
Step 2: Check syntax correctness
function onEdit(e) { /* code here */ } uses correct function declaration with parameter e and braces.
Final Answer:
function onEdit(e) { /* code here */ } -> Option A
Quick Check:
onEdit needs (e) parameter and braces [OK]
Hint: Include (e) parameter to access edit info in onEdit [OK]
Common Mistakes:
Omitting the (e) parameter in onEdit function
Using arrow function syntax which is invalid here
Missing parentheses or braces in function declaration
3. Given this onEdit function in Google Sheets Apps Script:
function onEdit(e) {
if (e.range.getA1Notation() === 'A1') {
e.source.getActiveSheet().getRange('B1').setValue('Edited!');
}
}
What happens when you edit cell A1?
medium
A. Nothing happens
B. Cell A1 will be cleared
C. Cell B1 will display the text 'Edited!'
D. An error occurs because of wrong syntax
Solution
Step 1: Understand the trigger condition
The function checks if the edited cell is 'A1' using e.range.getA1Notation().
Step 2: Analyze the action on condition true
If true, it sets the value of cell 'B1' to 'Edited!' on the active sheet.
Final Answer:
Cell B1 will display the text 'Edited!' -> Option C
Quick Check:
Editing A1 triggers B1 = 'Edited!' [OK]
Hint: Check edited cell with e.range.getA1Notation() [OK]
Common Mistakes:
Assuming the edited cell changes instead of B1
Thinking the script clears A1
Believing the code has syntax errors
4. This onOpen function is intended to show a custom menu, but it doesn't work:
function onOpen() {
var ui = SpreadsheetApp.getUi;
ui.createMenu('My Menu')
.addItem('Say Hello', 'sayHello')
.addToUi();
}
What is the error?
medium
A. Missing parentheses after getUi
B. Function onOpen must have parameter e
C. createMenu is not a valid method
D. addItem requires two parameters
Solution
Step 1: Identify method call syntax
The code uses SpreadsheetApp.getUi without parentheses, so it references the function but does not call it.
Step 2: Correct method call
Adding parentheses getUi() calls the method and returns the UI object needed to create the menu.
Final Answer:
Missing parentheses after getUi -> Option A
Quick Check:
Method calls need () to execute [OK]
Hint: Always add () to call methods like getUi() [OK]
Common Mistakes:
Forgetting parentheses on method calls
Thinking onOpen needs parameters
Misunderstanding addItem parameters
5. You want to create an onEdit trigger that automatically timestamps column B when a user edits column A in the same row. Which script correctly does this?
hard
A. function onEdit(e) {
if (e.range.getColumn() === 2) {
var row = e.range.getRow();
e.source.getActiveSheet().getRange(row, 1).setValue(new Date());
}
}
B. function onEdit(e) {
if (e.range.getColumn() === 1) {
e.source.getActiveSheet().getRange('B' + e.range.getRow()).setValue('Timestamp');
}
}
C. function onEdit(e) {
if (e.range.getRow() === 1) {
e.source.getActiveSheet().getRange('B1').setValue(new Date());
}
}
D. function onEdit(e) {
if (e.range.getColumn() === 1) {
var row = e.range.getRow();
e.source.getActiveSheet().getRange(row, 2).setValue(new Date());
}
}
Solution
Step 1: Check column condition for edits in column A
The script must detect edits in column 1 (A) using e.range.getColumn() === 1.
Step 2: Set timestamp in column B of the same row
It gets the row number and sets the current date/time in column 2 (B) of that row using setValue(new Date()).
Final Answer:
function onEdit(e) {
if (e.range.getColumn() === 1) {
var row = e.range.getRow();
e.source.getActiveSheet().getRange(row, 2).setValue(new Date());
}
} -> Option D
Quick Check:
Detect col A edit, timestamp col B same row [OK]
Hint: Use getColumn() and getRow() to target cells dynamically [OK]
Common Mistakes:
Checking wrong column number for edits
Using fixed cell references instead of dynamic rows