Hi Michelleaneous,
Your code looks correct for handling e.source, which is a spreadsheet object.
https://developers.google.com/apps-script/guides/triggers/events
Likely the error is could be you ran the function from the IDE and not the event itself, causing the object not to be declared. You can wrap some error code around it for testing so you can run from the IDE, but I probably wouldn’t keep in … just for while developing it makes it easier than having to ensure the event ran. See below:
function onEdit(e) {
let spreadsheet;
try {
spreadsheet = e.source
}
catch (err) {
if (!spreadsheet) { spreadsheet = SpreadsheetApp.getActiveSpreadsheet() }
}
const sheet = spreadsheet.getActiveSheet()
console.log(sheet.getName())
}