Count Vowels
JavaScript
easy
10 mins
Write a function countVowels that takes a string as input and returns the number of vowels in that string. Vowels include both lowercase and uppercase characters: 'a', 'e', 'i', 'o', 'u' and 'A', 'E', 'I', 'O', 'U'.
Example Inputs & Outputs
countVowels("hello") // → 2 (e, o) countVowels("JavaScript") // → 3 (a, a, i) countVowels("bcd") // → 0 countVowels("AEIOU") // → 5 countVowels("") // → 0
Constraints & Edge Cases
- Input will always be a string.
- String may contain spaces, punctuation, or numbers — these are not vowels.
- Function should be case-insensitive (handle both uppercase and lowercase).
- An empty string should return
0.
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
