Ad

A function that takes in a string and returns how many words it has. like so:

  wordCount("Bob the tomato") => 3

ignore spelling

  wordCount("B B H JK") => 4
function wordCount(str) {
  var words = 1;
  for(var i = 1; i < str.length; i++) {
    if(str[i] == " " && str[i - 1] !== " "&& str[i + 1] !== " ") {
      words++;
    }
  }
  return words;
}