function countTheWords() {
var word = "";
var num;
num = num + 1;
How do i add a counter to this? I'm trying to count how many words there are in a sentence. I have a test next week that I am studying for and I am stuck on this. I know that what I have is wrong, so please guide me on how I can count the number of words in a sentence.
do {
word = prompt("Enter a sentence one word at a time. Enter exit to finish your sentence.");
word = word + 1;
}while(word != "exit");
document.write("There are: " + word + " words in your sentence");
}