Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

initializing variables

Status
Not open for further replies.

MarkJ2

Technical User
Sep 25, 2001
17
US
I am writing a script that will convert the string the user has entered into pig latin. I have that down, but I want to change the rules slightly so that the words are only changed if the word begins with a consonant. I was thinking of doing one of two things:

var vowel = a, e, i, o, u; //is this even possible?

function pigLatin(theArray)
//there is other code in the function I don't need help
//with, just what's below.

if ( string.charAt(0) == vowel )
{
//body statements here. i.e. don't change word and just
return it unchanged;
}

or

if ( string.charAt(0) == "a" || string.charAt(0) == "e" ||
string.charAt(0) == "i" || string.charAt(0) == "o" ||
string.charAt(0) == "u" )
{
//body statements. same as above;
}

or if there is an easier way...let me know.

Thanks alot

Mark
 
Try this:

function pigLatin(theArray) {
// assuming the var theWord holds the word

var Pattern = new Object();
Pattern.vowels = /^[aeiouAEIOU]/;
var foundVowel = Pattern["vowels"].exec(theWord);

if (!foundVowel) { // change the word
}
}

Hope that helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top