Computer Science, asked by totaldancediva2166, 11 months ago

Find character and word count in str in javascript

Answers

Answered by prabhushankar1771
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