I’m trying my hand on JavaScript and my browser refuses to execute this program I have written using switch case function. The goal is to find the number of vowels in a string (consider all are in-putted in lower case)
When I click the ‘submit’ button the text from the box goes away but nothing happens.
The alert “hello” also does not appear, so I’m assuming that the function is not even being executed.
<html>
<head>
<script>
function vow(form)
{
alert("hello");
var a = new Array(10);
a = form.t1.value;
var flag = 0;
var i;
for(i=0;i<10;i++)
{
switch (a[i])
{
case 'a':
flag++;
break;
case 'e':
flag++;
break;
case 'i';
flag++;
break;
case 'o';
flag++;
break;
case 'u';
flag++;
break;
}
}
alert(flag);
}
</script>
</head>
<body>
<form>
<input type="text" name="t1">
<input type="submit" value="SUBMIT" onClick="vow(this.form)"/>
</form>
</body>
</html>
You are using
;instead of:.Same case for
oandu.Update:
I also show a (memory intensive) alternative version:
Update:
You can see it here.