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

24th Dec 2016, 8:26 PM
Nashwan Aziz
Nashwan Aziz - avatar
10 Answers
+ 6
Nice one @visph ! (didn't consider using RegExp...) ^_^
24th Dec 2016, 9:04 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
I think I fixed it, try again...
24th Dec 2016, 8:50 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 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"); };
24th Dec 2016, 8:59 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 4
function countv(t) { return t.match(/(a|e|i|o|u)/gi).length; }
24th Dec 2016, 8:53 PM
visph
visph - avatar
+ 4
function countv2(t,v) { r=new RegExp(v,"g"); return t.match(r).length; }
24th Dec 2016, 9:15 PM
visph
visph - avatar
+ 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 .
24th Dec 2016, 9:10 PM
Nashwan Aziz
Nashwan Aziz - avatar
+ 1
but not execut
24th Dec 2016, 8:45 PM
Nashwan Aziz
Nashwan Aziz - avatar
+ 1
write to java script or web
24th Dec 2016, 8:51 PM
Nashwan Aziz
Nashwan Aziz - avatar
+ 1
thank you all
24th Dec 2016, 9:03 PM
Nashwan Aziz
Nashwan Aziz - avatar
+ 1
execute naw . th
24th Dec 2016, 9:06 PM
Nashwan Aziz
Nashwan Aziz - avatar