Extending the String Class

Published by Helen Yu in

Make two methods:

  1. consonants(word) which returns the number of consonants in a word when called.
  2. vowels(word) which returns the number of vowels in a word when called.

Examples

"hello".consonants ➞ 3
"hello".vowels ➞ 2

"greatly".consonants ➞ 5
"greatly".vowels ➞ 2

"Smithsonian".consonants ➞ 7
"Smithsonian".vowels ➞ 4

Notes

  • Vowels are: a, e, i, o, u.
  • Case insensitive
Watch a quick demo on how Edabit works.