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;
If you replace text with 'This is a word counter' then you get the correct answer of 5.
text
'This is a word counter'
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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:
If you replace
text
with'This is a word counter'
then you get the correct answer of 5.