The Script Editor in Google Sheets allows you to:
Think about what scripting means and how it can help with repetitive tasks.
The Script Editor is used to write custom code (scripts) that can automate tasks or add new functions to your Google Sheets. It is not for formatting or chart creation.
Consider this Google Apps Script code run from the Script Editor:
function logSum() {
var a = 5;
var b = 7;
Logger.log(a + b);
}What will appear in the Logs after running logSum()?
Logger.log prints the value of the expression inside the parentheses.
The script adds 5 and 7, resulting in 12, which is logged. It does not concatenate as strings.
You want to write a script that works on the currently open spreadsheet. Which function should you use?
Think about which function returns the spreadsheet you are currently working on.
getActiveSpreadsheet() returns the spreadsheet currently open in the user's browser. The others either open a new spreadsheet or get the user interface.
Which method should you use to add a custom menu to the Google Sheets interface?
Menus are part of the user interface, so you need to get the UI first.
The correct way is to get the UI with getUi(), create the menu, add items, and then add it to the UI with addToUi(). Other options are invalid or incomplete.
Given this script run from the Script Editor:
function writeValue() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.getRange('A1').setValue('Hello');
sheet.getRange('A1').setValue(sheet.getRange('A1').getValue() + ' World');
}What will cell A1 contain after writeValue() runs?
Look at how the script reads and updates the cell value step by step.
The script first sets A1 to 'Hello'. Then it reads A1's value ('Hello'), adds ' World' to it, and writes back 'Hello World'.