Build the 2D array, write it once
The core idea is to never call a Sheets API method inside a loop. Every call to setBackground (singular) on an individual cell crosses the Apps Script quota boundary — 30 seconds of execution time is easy to hit on a 1,000-row sheet if you're painting cell by cell. Instead, build a JavaScript array-of-arrays where each inner array is one full row of hex color strings, then hand the whole thing to setBackgrounds (plural) on a single range. One network round-trip, regardless of row count.
getLastRow() and getLastColumn() give you the occupied extent of the sheet. Using those instead of a hardcoded range means the script stays correct when someone adds columns later. If your sheet has a header row you want left untouched, change the range start: getRange(2, 1, numRows - 1, numCols) and start the loop index at 1 so parity math still gives you even/odd relative to data rows, not the absolute sheet row number. I keep that offset logic in a comment the first time I hand this to a non-developer — it trips people up every single time.