0
0
Google Sheetsspreadsheet~10 mins

Triggers (onEdit, onOpen) in Google Sheets - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple onOpen trigger function that shows an alert.

Google Sheets
function onOpen() {
  SpreadsheetApp.getUi().[1]('Welcome!');
}
Drag options to blanks, or click blank then click option'
Aalert
BshowAlert
CdisplayMessage
Dpopup
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist like showAlert or popup.
2fill in blank
medium

Complete the code to create an onEdit trigger that logs the edited cell's value.

Google Sheets
function onEdit(e) {
  var editedValue = e.range.get[1]();
  Logger.log(editedValue);
}
Drag options to blanks, or click blank then click option'
AData
BText
CContent
DValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using getText() which returns formatted text, not the actual value.
3fill in blank
hard

Fix the error in the onEdit function to check if the edited cell is in column 2.

Google Sheets
function onEdit(e) {
  if (e.range.getColumn() [1] 2) {
    Logger.log('Edited column 2');
  }
}
Drag options to blanks, or click blank then click option'
A=
B==
C===
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using single equals = instead of comparison operator.
4fill in blank
hard

Fill both blanks to create an onEdit trigger that only runs when editing the first sheet and column 1.

Google Sheets
function onEdit(e) {
  var sheet = e.range.getSheet();
  if (sheet.getName() [1] 'Sheet1' && e.range.getColumn() [2] 1) {
    Logger.log('Edit in Sheet1 column 1');
  }
}
Drag options to blanks, or click blank then click option'
A==
B=
C===
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment operator = instead of comparison.
5fill in blank
hard

Fill all three blanks to create an onOpen trigger that adds a custom menu with one item.

Google Sheets
function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu([1])
    .addItem([2], [3])
    .addToUi();
}
Drag options to blanks, or click blank then click option'
A'Custom Menu'
B'Say Hello'
C'sayHello'
D'Menu Item'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the item label and function name strings.