मराठी
महाराष्ट्र राज्य शिक्षण मंडळएचएससी विज्ञान (सामान्य) इयत्ता १२ वी

Write event driven JavaScript program for the following. Accept any string from user and count and display number of vowels occurs in it. - Information Technology

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.

थोडक्यात उत्तर

उत्तर

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
JavaScript Built-in Objects - String
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 3: Advanced Javascript - Exercises [पृष्ठ ५१]

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×