I\'m supposed to write a function that takes a character (i.e. a string of length 1) and returns true if it is a vowel, false otherwise. I came up with two functions, but do
function isVowel(char) { if (char.length == 1) { var vowels = "aeiou"; var isVowel = vowels.indexOf(char) >= 0 ? true : false; return isVowel; } }
Basically it checks for the index of the character in the string of vowels. If it is a consonant, and not in the string, indexOf will return -1.
indexOf