A. A new menu named 'My Menu' appears with an item 'Say Hello' that runs the sayHello function
B. The sheet background changes to say 'Hello'
C. A popup appears saying 'Hello' automatically
D. Nothing happens until you run the script manually
Solution
Step 1: Understand the code's purpose
The code creates a new menu called 'My Menu' in the Google Sheets UI.
Step 2: Analyze the menu item
The menu has one item labeled 'Say Hello' that runs the function named 'sayHello' when clicked.
Final Answer:
A new menu named 'My Menu' appears with an item 'Say Hello' that runs the sayHello function -> Option A
Quick Check:
createMenu + addItem = new menu item [OK]
Hint: createMenu + addItem adds menu and function link [OK]
Common Mistakes:
Thinking the script changes sheet colors automatically
Expecting a popup without clicking menu
Assuming nothing happens without manual run
4. You wrote this onOpen() function but the custom menu does not appear:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Tools')
.addItem('Run Task', 'runTask')
}
What is the error preventing the menu from showing?
medium
A. addItem should be addMenu
B. Function name should be onStart()
C. Menu name 'Tools' is invalid
D. Missing call to addToUi() at the end
Solution
Step 1: Check the menu creation chain
The code creates a menu and adds an item but does not call addToUi().
Step 2: Understand addToUi() role
This method is required to actually add the menu to the Google Sheets UI.
Final Answer:
Missing call to addToUi() at the end -> Option D
Quick Check:
addToUi() adds menu to sheet [OK]
Hint: Always end menu chain with addToUi() [OK]
Common Mistakes:
Using wrong function name instead of onOpen
Thinking menu name is restricted
Confusing addItem with addMenu
5. You want to create a custom menu with two items: 'Start Process' running startProcess and 'Stop Process' running stopProcess. Which code snippet correctly creates this menu inside onOpen()?
hard
A. function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Process Control')
.addItem('Start Process')
.addItem('Stop Process')
.addToUi();
}
B. function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Process Control')
.addItem('Start Process', 'startProcess')
.addToUi()
.addItem('Stop Process', 'stopProcess');
}
C. function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Process Control')
.addItem('Start Process', 'startProcess')
.addItem('Stop Process', 'stopProcess')
.addToUi();
}
D. function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Process Control')
.addItem('Start Process', startProcess)
.addItem('Stop Process', stopProcess)
.addToUi();
}
Solution
Step 1: Check method chaining order
The menu is created, then two items are added with correct labels and function names as strings.
Step 2: Verify addToUi() is last
The chain ends with addToUi() to add the menu to the UI.
Step 3: Confirm function names are strings
Function names must be strings, not bare identifiers.
Final Answer:
Code snippet D correctly creates the menu with two items and adds it to the UI -> Option C
Quick Check:
Chain addItem with function names as strings, end with addToUi() [OK]
Hint: Chain addItem calls, end with addToUi() [OK]