Hi I am trying to count the vowels of the input of the form in my HTML using javascript currently with no success.
Here is my HTML
Replace your switch statement with
if(vowels.indexof(a[i]) > -1)
So
function vow(form){
var vowels = ['a', 'e', 'i', 'o', 'u'];
var a = form.CountVowels.value;
flag = 0;
for (var i = 0; i < a.length; i++){
if(vowels.indexof(a[i]) > -1){
flag++;
}
}
alert(flag);
}
If you want to stick with the switch statement, you can, but you were missing colons ':'
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
flag++;
break;
The first method is simpler as you are basically checking if the letter exists in the vowel array.