Workshop › 2048 › Step 4 of 26
Every value has its own color, looked up in a table keyed by the number: COLORS[value]. Empty cells stay light
brown; values past 2048 get a dark color.
```js
const COLORS = {
2: '#eee4da',
4: '#ede0c8',
8: '#f2b179',
16: '#f59563',
32: '#f67c5f',
64: '#f65e3b',
128: '#edcf72',
256: '#edcc61',
512: '#edc850',
1024: '#edc53f',
2048: '#edc22e',
}
const value = board[row][col]
ctx.fillStyle = value === 0 ? '#cdc1b4' : COLORS[value] || '#3c3a32'
```COLORS is an object used as a lookup table: COLORS[8] is '#f2b179'.value === 0 ? a : b picks the empty color for 0, otherwise the table's color.COLORS[4096] is undefined, so || '#3c3a32' gives a dark color for anything past 2048.TOP write the COLORS table.draw, replace the '#cdc1b4' color line with the two new lines.Skills: Arrays and objects
← A grid of numbers Numbers on the tiles →