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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if/else help 2

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
I am working in Flash 5.

I have an input field with the variable name of "one". The user enters his/her answer in the field then presses an Enter button which contains:

Code:
on (release, keyPress &quot;<Enter>&quot;) {
    if (one eq &quot;meatball&quot;) {
        trace (&quot;correct&quot;);
    } else {
        trace (&quot;incorrect&quot;);
    }
}

This works fine.

What I want to do is allow for uppercase, lowercase, first letter caps. (MEATBALL, meatball, Meatball)

I have tried this but all three answers come up as incorrect:

Code:
on (release, keyPress &quot;<Enter>&quot;) {
    if (one eq [&quot;meatball&quot; | &quot;Meatball&quot; | &quot;MEATBALL&quot;]) {
        trace (&quot;correct&quot;);
    } else {
        trace (&quot;incorrect&quot;);
    }
}

Thanks for your help.
 
If you only want those 3 possibilities, try this:

if ((one == &quot;meatball&quot;) || (one == &quot;MEATBALL&quot;) || (one == &quot;Meatball&quot;)) {
trace (&quot;Correct!&quot;);
} else {
trace (&quot;Incorrect!&quot;);
}

Regards,
mywink2.gif
ldnewbie
 
Alternatively you could use a handy method of the String object so that you only have one option to deal with.

toLowerCase() takes your input and turns everything to lowercase so it doesn't matter if the input was capitalised, all uppercase or even a random combination of cases.

myString = new String(one);
if (myString.toLowerCase() == &quot;meatball&quot;) {
trace (&quot;correct&quot;);
} else {
trace (&quot;incorrect&quot;);
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top