Here is a small function that counts words in a text:
javascript
// Count the words in a piece of textfunctioncountWords(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