Build a Sentence Analyzer - Step 7

Tell us what’s happening:

How so i detect a sentence full of spaces? This seems to skip every 2nd index?

Your code so far

function getWordCount(sentence){

 let wordCount = sentence.split(" ")

for (let char in wordCount){
  if (wordCount[char]== ''){
    wordCount.splice([char], 1)
  }
}
 return wordCount.length

}

console.log(getWordCount("   a"))

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (iPad; CPU OS 18_3_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/145.0.7632.108 Mobile/15E148 Safari/604.1

Challenge Information:

Build a Sentence Analyzer - Step 7

I have found a way.

removed by moderator

Just added a variable to contain the amount of spaces in the sentence and subtracted it out,of the length of the sentence.

Congratulations on solving the challenge! You should be proud of your achievement…we are! But we are removing your working solution, so it is not available to others who have not yet done the work to get there. Again, congrats!

it’s a bad idea to iterate over the array and change it while you are iterating, please consider never doing this again