Build a Sentence Analyzer - Step 7

Tell us what’s happening:

The code works, but the test failed. What am i doing wrong?

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){
  let count = 0
  let word = " "
  for (const char of sentence){
    if ( word.includes(char)){
      count++
    }
  }
  return count + 1
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0

Challenge Information:

Build a Sentence Analyzer - Step 7

When I test your function I get this feedback

Your getWordCount function should return the correct word count for an empty string, or a string only with spaces.

Have you tested these cases?

When I added
const wordCount = getWordCount(“When are you gonna start learning to code?”) console.log(wordCount)
the console showed 8, but the same error you described.

What does the error tell you?

It counts the correct number of words :white_check_mark:

Read the error. Is there anything else you should test?