Build a Sentence Analyzer - Step 7

Tell us what’s happening:

what is going on with getWordCount function?
I cant get the the count of word in any sentence.

Your code so far

function getVowelCount(sentence) {
  const vowels = "aeiou";
  let count = 0;

  for (const char of sentence.toLowerCase()) {
    if (vowels.includes(char)) {
      count++;
    }
  }
  return count;
}

const vowelCount = getVowelCount("Apples are tasty fruits");
console.log(`Vowel Count: ${vowelCount}`);

function getConsonantCount(sentence) {
  const consonants = "bcdfghjklmnpqrstvwxyz";
  let count = 0;

  for (const char of sentence.toLowerCase()) {
    if (consonants.includes(char)) {
      count++;
    }
  }
  return count;
}

const consonantCount = getConsonantCount("Coding is fun");
console.log(`Consonant Count: ${consonantCount}`);

function getPunctuationCount(sentence) {
  const punctuations = ".,!?;:-()[]{}\"'–";
  let count = 0;

  for (const char of sentence) {
    if (punctuations.includes(char)) {
      count++;
    }
  }
  return count;
}

const punctuationCount = getPunctuationCount("WHAT?!?!?!?!?");
console.log(`Punctuation Count: ${punctuationCount}`);


// User Editable Region

function getWordCount(sentence){
  if (sentence=='' | ' '){
    return 0
  }
  return sentence.split(" ").length
}
console.log(getWordCount('g g'))

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Challenge Information:

Build a Sentence Analyzer - Step 7

what do you think this line is doing?

if the sentence s empty, return zero

are you sure it does that?
put your condition in console.log, see what it evaluates to

If I change your code to

function getWordCount(sentence){
  console.log("condition: ", sentence=='' | ' ')
  if (sentence=='' | ' '){
    return 0
  }
  return sentence.split(" ").length
}

to print the condition, what is in the console is:

condition:  0
condition:  0
condition:  0
condition:  0
condition:  0
condition:  0
condition:  0
condition:  0
condition:  1
condition:  0

is that what you expect?

You may want to check if | is the right operator to use

I solved it. Thank you
function getWordCount(sentence){
if (sentence.trim()==‘’){
return 0
}
return sentence.split(" ").length
}
console.log(getWordCount(‘’))