Advertisements
Advertisements
प्रश्न
Write event driven JavaScript program for the following.
Accept any string from user and count and display number of vowels occurs in it.
संक्षेप में उत्तर
Advertisements
उत्तर
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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
