Library › Coding AI › Finance and accounting
Lock a closed month's tab with a short Apps Script
Practice: Setting limits and rules. About 5 minutes.
About this exercise
Write a Google Apps Script function named lockMonth that protects the whole tab named 2026-10 after the October close. The protection description must be Closed - do not edit, and the only editor left must be the controller, kofi.mensah@northgate.example: remove everyone else and turn off domain editing. You'll run it by hand, so no menus, triggers, logging or try/catch. One code block, at most 12 lines, then under 25 words outside the code.
Common mistakes when you ask AI for this
- Not naming the tab. The AI protects the active sheet or a range, so the wrong thing gets locked. Try: Add: "Protect the whole tab named 2026-10."
- Leaving the label open. The AI writes its own description, so people don't see why it's locked. Try: Add: "Description: Closed - do not edit."
- Not saying who keeps access. Protection keeps current editors by default, so Ama and the whole domain can still edit. Try: Add: "Remove all editors, add only Kofi, turn off domain editing."
- Getting a menu of options. The AI likes to offer two or three versions of the script, so you're left to pick and test them yourself. Try: Add: "Give one script only, in one code block, no alternatives."
- Getting a tutorial. By default the AI explains every part of the code at length, which you then have to scroll past. Try: Add: "After the code, one line under 12 words. Nothing else."
What a strong prompt includes
- Names the function and tab
- Sets the description
- Says who keeps access
- Rules out extras
- Caps the code length
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)