Complete the code to create a simple onOpen trigger function that shows an alert.
function onOpen() {
SpreadsheetApp.getUi().[1]('Welcome!');
}The alert method shows a popup message when the spreadsheet opens.
Complete the code to create an onEdit trigger that logs the edited cell's value.
function onEdit(e) {
var editedValue = e.range.get[1]();
Logger.log(editedValue);
}The getValue() method returns the value of the edited cell.
Fix the error in the onEdit function to check if the edited cell is in column 2.
function onEdit(e) {
if (e.range.getColumn() [1] 2) {
Logger.log('Edited column 2');
}
}= instead of comparison operator.Use == to compare values in JavaScript. Single = is assignment and causes error.
Fill both blanks to create an onEdit trigger that only runs when editing the first sheet and column 1.
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');
}
}= instead of comparison.Use == to compare both sheet name and column number.
Fill all three blanks to create an onOpen trigger that adds a custom menu with one item.
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu([1])
.addItem([2], [3])
.addToUi();
}The menu is named 'Custom Menu'. The item label is 'Say Hello' and the function called is 'sayHello'.