Advertisements
Advertisements
Question
Write event driven JavaScript program for the following.
Accept any string from user and count and display number of vowels occurs in it.
Answer in Brief
Advertisements
Solution
Coding:
<html>
<script type="text/javascript">
var n, i, ch, cnt = 0;
n = prompt("Enter a String");
for (i = 0; i < n.length; i++) {
ch = n.charAt(i);
if (ch == 'a' || ch == ' A' || ch == 'e' || ch == 'E' || ch == 'i' ||
ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U') {
cnt = cnt + 1;
}
}
document.write("Number of vowels in string are " + cnt);
</script>
</html>shaalaa.com
Is there an error in this question or solution?
