Find character and word count in str in javascript
Answers
Answered by
0
Answer:
function WordCount(str) { var totalSoFar = 0; for (var i = 0; i < WordCount.length; i++) if (str(i) === " ") { // if a space is found in str totalSoFar = +1; // add 1 to total so far } totalsoFar += 1; // add 1 to totalsoFar to account for extra space since 1 space = 2 words } console.log(WordCount("Random String"));
I think I have got this down pretty well, except I think that the if statement is wrong. How do I say if(str(i) contains a space, add 1.
Similar questions
English,
6 months ago
Environmental Sciences,
6 months ago
English,
6 months ago
English,
1 year ago
Math,
1 year ago