7. Write a JavaScript function that accepts a string as a parameter and counts the number of vowels within the string. Note : A | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

7. Write a JavaScript function that accepts a string as a parameter and counts the number of vowels within the string. Note : A

7. 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

18th Dec 2016, 8:37 PM
Mohameddd Alanzy
Mohameddd Alanzy - avatar
2 Answers
+ 2
i will not write code but just give u idea make a variable having value of that string. then iterate over string using another variabke lets say i. we also have to count so initialise a counter above with 0. and inside of loop check whether array[i]==='a'. if yes then increment counter. similarly check for capital A. and this process can be repeated for all vowels. u can optimise this also accordingly
18th Dec 2016, 9:21 PM
manish rawat
manish rawat - avatar
+ 1
No, i is a string not an array. To make it an array, you can do var iArr = i.split("") so each and every of the characters becomes a member of an array.
19th Dec 2016, 1:46 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar