I would be delighted if someone could look into my code. I have been trying to return the total number of vowels in a given string. I want my code to take into account of cases of the letter, any empty spaces in the string and also absence of vowel. I believe there is something wrong with my if-statement which is returning 0 for the string input "Crypt" and "Crypto"
function countVowels(str) {
let count = 0;
let arr = str.toLowerCase().split("")
let vowels = ["a","e","i","o","u"]
console.log(arr)
for (let i = 0; i < str.length; i++){
if (arr[i].includes(vowels)){
count++
} else {
return 0
}
}
return count
}
console.log(countVowels("Crypto"))
console.log(countVowels("Crypt"))
(arr[i].includes(vowels))- other way around.array.includes(searchElement);You search your arr[i] in the vowels array.return 0immediately as soon as you find the first non-vowel.'Café'?