Below some javascript code that should check wether it's one of those letters or not. However when I type "Hallo" for example it also counts the 'H', 'L', 'L
woord.charAt(i) == 'a' || 'e' || 'i' || 'o' || 'u'
What did I do wrong ?
(woord.charAt(i) == 'a') || 'e' || 'i' || 'o' || 'u'
// evaluates to true or 'e'
It looks like you are trying to write code like you'd write a sentence, which doesn't translate well in this case. The above code shows what really happens with that expression.
You need to compare the character against each string individually or write a regular expression. The regex is more compact and would look like:
/[aeiou]/.test(word.charAt(i))
Try using a different approach to the problem
var c = woord.charAt(i);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
vowels++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With