Workshop › Wordle-style Word Guess › Step 10 of 26
Backspace removes the last letter: slice(0, -1) is everything but the last character. Since type now gets keys that
are not letters, it checks for a letter itself too.
```js
function type(key) {
if (key === 'Backspace') current = current.slice(0, -1)
else if (/^[a-z]$/.test(key) && current.length < 5) current += key
}
if (key === 'Backspace' || /^[a-z]$/.test(key)) {
```slice(0, -1) takes the text from the start up to, but not including, the last character. Negative positions count
from the end.else if is checked only when the first if was false.type, replace the line with the two lines shown.key === 'Backspace' || to the if. Press Run.Skills: Keyboard and mouse input
← Show the letters Leave shortcuts alone →