Workshop › Text detective › Step 3 of 13

Update as you type

What we are doing

Right now the count is made once, when the page opens. We put it in a function and run it again every time the text changes.

```js
function update() {
  result.textContent = 'Characters: ' + box.value.length
}

box.addEventListener('input', update)
update()
```

What it means

Your turn

Wrap the last line in function update() { ... }, then add the listener and the first call.

Skills: Functions, Keyboard and mouse input

All steps

  1. Read the text
  2. Count the characters
  3. Update as you type
  4. Split into words
  5. The extra-space trap
  6. An empty box has no words
  7. Count each word
  8. Drop the punctuation
  9. The most common word
  10. Shift a letter
  11. Encode a whole text
  12. The secret line
  13. Build it yourself: crack the code