Count the words in JavaScript

<SCRIPT>
function countWords(str){
   var count = 0;
   words = str.split(" "); 
    for (i=0 ; i < words.length ; i++){
       // inner loop -- do the count
       if (words[i] != "")
          count += 1; 
    }

   document.theForm.results.value = 
      "There are " +
      count +
      " words in the text string you entered!";
}
</SCRIPT>