I'm trying to write a javascript counter function that takes a text argument that counts the number of words in the text.
The return output also has to be displayed as a single object.
I'm trying to write a javascript counter function that takes a text argument that counts the number of words in the text.
The return output also has to be displayed as a single object.
try to use text.split(' ').length
var countOf = function(text){
return text.split(' ').length
}
the way to do is to count every is_space() in the string that is not preceded by an other is_space(), add to the result the last word if it remain.