Workshop › Text detective › Step 6 of 13

An empty box has no words

What we are doing

Clear the box and the detective still says "Words: 1": splitting an empty text gives one empty piece. We handle that case on its own.

```js
const text = box.value.trim()
const words = text === '' ? [] : text.split(/\s+/)
```

What it means

Your turn

Replace the words line with the two lines.

Skills: Types and values

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