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
The vow
function expects the form as a parameter, but you're not passing it. Give your form an ID so you can look it up and pass it.
button1.onclick = function() {
vow(document.getElementById('demo_form'));
};
function vow(form) {
var a = form.CountVowels.value;
flag = 0;
for (var i = 0; i < a.length; i++) {
switch (a[i]) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
flag++;
break;
}
}
alert(flag);
}
function init() {
var button1 = document.getElementById("btn1")
button1.onclick = function() {
vow(document.getElementById('demo_form'));
};
}
window.onload = init;
You were also missing the :
character after each case
statement.