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!"; } Enter a text string: Results