function getWordCount(str) {
return str.trim().split(/\s+/).length;
}
const sentence = 'Give me the count of all words in this sentence!';
console.log('Sentence: '+sentence);
console.log('Total words: '+getWordCount(sentence));
This Pen doesn't use any external CSS resources.