Build a Sentence Analyzer - Step 1

Tell us what’s happening:

I don’t get why it does not work. I’ve tried several sentences and it worked. Am I missing some vowels in the list?

Your code so far


// User Editable Region

function getVowelCount(sentence){
  const array = sentence.split("");
  let countVowel = 0;
  for (let i = 0; i < array.length; i++){
    if (array[i] == "a" || array[i] == "e" || array[i] == "i" || array[i] == "o" || array[i] == "u" || array[i] == "y") {
      countVowel += 1;
    }  
  }
  return countVowel;
}

console.log(getVowelCount("Ceci est un test"))

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

Challenge Information:

Build a Sentence Analyzer - Step 1

Welcome to the forum @NicoPi

When the sentence is "Apples are tasty fruits" , the getVowelCount function should return 7 .

Your function returns 6.
There are seven vowels in the sentence, how is one of them different to the others?

Happy coding

Hi,

Thank you for your answer. But the code return 7 with your sentence. I have tried to toLowerCase the sentence first, but then it does not accept the sentence “Apples are tasty fruits” because it returns 8, and the function should be case sensitive. I’m stucked :slight_smile:

So now you are getting an extra vowel.

Starting from 1, place a number below each vowel in the sentence.

If I add toLowerCase, yes I get one extra vowel (8) and the function should return 7. But the code returns 7. When I use the function in my initial post with the sentence Apples are tasty fruits the program returns me this:

// running tests
7
7. Your getVowelCount function should return the correct vowel count for any sentence.
// tests completed
// console output
7

Can you post the sentence from my first post, plus the numbering on a separate line?

It isn’t in the requirement, but one of your vowels are not considered a vowel by the test. Wikipedia says it is sometimes considered a vowel.


As an aside, you do not need to split a string to loop it or index into it.

Hi,
Here is the code:

function getVowelCount(sentence){
  const array = sentence.split("");
  let countVowel = 0;
  for (let i = 0; i < array.length; i++){
    if (array[i] == "a" || array[i] == "e" || array[i] == "i" || array[i] == "o" || array[i] == "u" || array[i] == "y") {
      countVowel += 1;
    }  
  }
  return countVowel;
}

console.log(getVowelCount("Apples are tasty fruits"))

Here is the return:

// running tests
7. Your getVowelCount function should return the correct vowel count for any sentence.
// tests completed
// console output
7

Hi both,

Ok I have the solution : remove the y from the list of vowels and lowerCase the initial sentence.
Because I had y in the list and not lowerCase, I had also 7 with the sentence "Apples are tasty fruits" but not for the good reason.

Thank you both :slight_smile:

1 Like