Tell us what’s happening:
How do I detect a string filled with spaces to put into my first if-statement. ’ ’ slips into the else statement.
Your code so far
// User Editable Region
function getWordCount(sentence){
let count=1;
if (sentence.length===0){
return 0
} else {for (const char of sentence) {
if (char===' '){
count++;
}
}
return count
}
}
console.log(getWordCount(' '))
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Challenge Information:
Build a Sentence Analyzer - Step 7