Let's go back to the exercise where we determined what is and is not a vowel. With Ruby, there's always more than one way to do something and get the same result. (TIMTOWTDI, kids.)
For the purposes of this exercise, we are assuming the vowels are a, e, i, o, and u
. Sorry, 'y'.
-
Write a method that returns whether a given letter is a vowel, using
if
andelsif
. -
Write a method that returns whether a given letter is a vowel, using a case statement.
-
Write a method that returns whether a given letter is a vowel without using
if
orcase
while all on a single line. -
Write a method that returns whether a given letter is a vowel without checking equality, or the use of
if
. Hint: use an array of vowels. -
Write a method that returns whether a given letter is a vower using the ternary operator.
-
Write a method that will evaluate a string and return the first vowel found in the string, if any.
-
Write a method that will evaluate a string and return the ordinal position (index) of the string where the first vowel is found, if any.
Hint: remember that every line of Ruby code has a return value, and that a method will return the result of the last operation.
View More Vowels on Learn.co and start learning to code for free.