New to javascript here. I'm trying to create a javascript function that takes a text argument and counts the number of words, characters, and spaces in the text.
I'm having trouble adding the "number of words" to my function:
function superCounter (string) {
var x = string.length,
numSpaces = 0;
for (var i = 0; i < x; i++) {
if (string.charAt(i) == " ") {
numSpaces++;
}
var y = 0 {
for (var i = 0; i < string.length,
if (string.charAt(i) === " ") {
y = +1;
}
y += 1;
}
return {
"characters" : x - numSpaces,
"spaces": numSpaces
};
}
superCounter("Work hard in silence, let success make the noise");