0
Write a JavaScript function that accepts a string as a parameter and counts the number of vowels within the string.
Note : As the letter 'y' can be regarded as both a vowel and a consonant, we do not count 'y' as vowel here. Example string : 'The quick brown fox' Expected Output : 5
10 ответов
+ 6
Nice one @visph ! (didn't consider using RegExp...) ^_^
+ 5
I think I fixed it, try again...
+ 5
var cnt = 0;
var str = [];
var mtc = "aeiou";
function vow(str){
for (var stp = 0; stp <= str.length - 1; stp++){
if (mtc.match(str[stp])){cnt++;}
}
return cnt;
}
window.onload = function(){
alert(vow(prompt("input string"))+" vowels");
};
+ 4
function countv(t) {
return t.match(/(a|e|i|o|u)/gi).length;
}
+ 4
function countv2(t,v) {
r=new RegExp(v,"g");
return t.match(r).length;
}
+ 2
9. Write a JavaScript function that accepts two arguments, a string and a letter and the function will count the number of occurrences of the specified letter within the string.
Sample arguments : 'w3resource.com', 'o'
Expected output : 2 .
+ 1
but not execut
+ 1
write to java script or web
+ 1
thank you all
+ 1
execute naw .
th