DEV Community

Discussion on: How to make a word counter with JavaScript🦸‍♂️

Collapse
 
mellen profile image
Matt Ellen

I haven't tried the full code, but from what I can see it specifically doesn't count spaces.

The part of the code that does the counting:

let totalWord = text.split(' ').length;
Enter fullscreen mode Exit fullscreen mode

If you replace text with 'This is a word counter' then you get the correct answer of 5.