Here is a small function that counts words in a text:
javascript
// Count the words in a piece of text
function countWords(text) {
  const words = text.trim().split(/\s+/).filter(Boolean);
  return words.length;
}

console.log(countWords("The quick brown fox jumps over the lazy dog and keeps running")); // 12