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
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
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
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.