Workshop › Wordle-style Word Guess › Step 22 of 26
The last row gets Enter (OK) and Backspace (DEL), one and a half keys wide. In KEY_ROWS they are written as >
and <; a small lookup turns them into their key names and labels, and each key now has its own width.
```js
const KEY_ROWS = ['qwertyuiop', 'asdfghjkl', '>zxcvbnm<'] // > is Enter, < is Backspace
const widths = [...row].map((k) => (k === '>' || k === '<' ? KEY_W * 1.5 : KEY_W))
const total = widths.reduce((a, b) => a + b, 0) + (row.length - 1) * 4
let x = (canvas.width - total) / 2
;[...row].forEach((k, i) => {
const [key, label] = { '>': ['Enter', 'OK'], '<': ['Backspace', 'DEL'] }[k] || [k, k]
rects.push({ key, label, x, y: KEYS_TOP + r * (KEY_H + 6), w: widths[i], h: KEY_H })
x += widths[i] + 4
})
```widths has one width per key: 48 for > and <, 32 for letters.reduce((a, b) => a + b, 0) adds them all up.['Enter', 'OK'] or ['Backspace', 'DEL']; for a letter it gives undefined, and || [k, k]
uses the letter for both.const [key, label] = ... names the two items of the pair.KEY_ROWS to '>zxcvbnm<' and add the comment.keyRects, replace the lines inside KEY_ROWS.forEach with the new ones. Press Run.Skills: Arrays and objects
← Tap a key Keys that remember →