Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Check vowel/consonant?

Is there any way to check whether the first letter of a variable is a vowel or a consonant? Thanks.

Comments

  • <<if "aeiou".indexOf($var[0]) !== -1>>
    ...Which leans pretty heavy on using various bits of javascript: strings are technically arrays, so if $var is "zebra", then $var[0] is 'z', and this checks to see if that first letter is inside a string of vowels. Sorry, 'y' isn't supported :V
  • [quote]Sorry, 'y' isn't supported :V

    I laughed. I meant to answer this question earlier, but I got totally sidetracked. This is the way to do it though. :)
  • xax wrote:
    strings are technically arrays
    This is actually more false than it is true. String.prototype.indexOf and Array.prototype.indexOf are entirely different functions with similar names. And any object can be indexed in an array-like fashion:

    ({})[2] = "Red";

    {
    2: "Red"
    }
    Strings are internally implemented as objects with numeric properties and a "magic" length property, but that's a far cry from an actual Array.
  • xax wrote:

    'y' isn't supported :V


    To handle the "and sometimes Y" case:
    <<if if ("aeiou".indexOf($var[0]) !== -1 or ("y".indexOf($var[0]) !== -1 and Math.random() >= .5))>>
Sign In or Register to comment.