Write a JavaScript program accept any string from user and count and display number of vowels occurs in it.
Answers
Answered by
2
Answer:
function getVowels(str) {
var vowelsCount = 0;
//turn the input into a string
var string = str.toString();
//loop through the string
for (var i = 0; i <= string.length - 1; i++) {
//if a vowel, add to vowel count
if (string.charAt(i) == "a" || string.charAt(i) == "e" || string.charAt(i) == "i" || string.charAt(i) == "o" || string.charAt(i) == "u") {
vowelsCount += 1;
}
}
return vowelsCount;
}
Similar questions
Computer Science,
2 months ago
Social Sciences,
2 months ago
Math,
4 months ago
Biology,
10 months ago
English,
10 months ago
English,
10 months ago