Workshop › Typing Rain › Step 11 of 33
Which word are you typing? You never say; the game works it out. The first letter you type locks on to a word starting with it. If several match, the lowest one is the most urgent.
```js
let target // the word being typed, or null
let typed // how many letters of the target are typed
target = null
typed = 0
function type(key) {
if (!target) {
// Lock on to the lowest word starting with this letter: it is the most urgent.
const options = words.filter((w) => w.text[0] === key).sort((a, b) => b.y - a.y)
if (options.length === 0) return
target = options[0]
typed = 0
}
}
```target is null (nothing) until a word is chosen; typed counts its letters done.w.text[0] is a word's first letter. filter keeps the words starting with key.sort((a, b) => b.y - a.y) orders them by y, largest first, so options[0] is the lowest.return leaves at once.let words write let target and let typed.reset, under words = [], write target = null and typed = 0.reset, after an empty line, write type.Skills: Game states, Arrays and objects
← Gone past the ground Listen to the keyboard →