JavaScript Basics: Count the words in a string

Posted 2 years ago

This is a quick function to count the words in a given string.


    <script>
      function wordCount(str){
        return str.split(' ').length;
      }

      console.log(wordCount('Hello, how are you?'))
    </script>