Build a Sentence Analyzer - Step 1

Tell us what’s happening:

Can’t pass and can’t figure out why.
3. Your getVowelCount function should return a number.
It does..
4. When the sentence is “Apples are tasty fruits”, the getVowelCount function should return 7.
It does..
5. When the sentence is “Hello, World!”, the function should return 3.
It does..
6. Your vowel count should be case-insensitive.
It is..
7. Your getVowelCount function should return the correct vowel count for any sentence.
Checked with empty strings, no vowel strings. It does..

Your code so far


// User Editable Region

function getVowelCount(sentence) {
  const vowels = 'aeiouAEIOU';
  let count = 0;
  for (char of sentence) {
    if (vowels.includes(char)) {
      count++;
    }
  }
  return count;
};

// tests done outside in VScode
console.log(getVowelCount("Apples are tasty fruits")); // 7
console.log(getVowelCount("Hello, World!")); // 3
console.log(getVowelCount('ghjk')) // 0
console.log(getVowelCount('')) // 0
console.log(getVowelCount('aeiouAEIOU')) // 10

// 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/140.0.0.0 Safari/537.36

Challenge Information:

Build a Sentence Analyzer - Step 1

https://www.freecodecamp.org/learn/full-stack-developer/workshop-sentence-analyzer/step-1

Do you see a reference error in the console?

There is something missing in this line. Look up the syntax of for … of loops if you can’t see what’s missing.

1 Like

I swear I read earlier that it was optional. Thank you.

1 Like

declaring variables is never optional

1 Like