Complete the code to create a custom menu in Google Sheets.
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('[1]')
.addItem('Show Alert', 'showAlert')
.addToUi();
}The createMenu method needs the menu name as a string. 'Custom Menu' is a clear and common choice.
Complete the code to add a menu item that calls the function 'showAlert'.
ui.createMenu('Custom Menu') .addItem('[1]', 'showAlert') .addToUi();
The addItem method takes the menu item name as the first argument. 'Show Alert' matches the function name and is user-friendly.
Fix the error in the code to properly add the custom menu when the spreadsheet opens.
function onOpen() {
var ui = SpreadsheetApp.getUi()
ui.createMenu('Custom Menu')
.addItem('Show Alert', [1])
.addToUi();
}The second argument to addItem must be a string with the function name, so it needs quotes like 'showAlert'.
Fill both blanks to create a menu with two items calling different functions.
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu')
.addItem('[1]', 'showAlert')
.addItem('[2]', 'showPrompt')
.addToUi();
}The menu items should have clear names matching their functions: 'Show Alert' and 'Show Prompt'.
Fill all three blanks to create a menu with three items and correct function names.
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('[1]')
.addItem('Show Alert', '[2]')
.addItem('Show Prompt', '[3]')
.addToUi();
}The menu name is 'Custom Menu'. The function names must be strings matching the functions: 'showAlert' and 'showPrompt'.