Thread: button question
View Single Post
Old 01-11-2013, 11:27 PM   PM User | #10
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,567
Thanks: 62
Thanked 4,058 Times in 4,027 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
First of all, if you use a <select> as I showed, you avoid the problem of upper/lower case.

Secondly, a switch( ) is by far not the most elegant way to do this. See my scheme.

But if you must use a switch and you must allow human fallible input, then you could do this:
Code:
switch ( planet )
{
    case "Mercury": case "mercury": case "MERCURY":
        info = "The planet closest to the sun.";
        break;
    case "Venus": case "venus": case "VENUS":
        ...
}
Do *NOT* forget the break after each same-case-action set!

But better than that would be:
Code:
switch ( planet.toLowerCase() )
{
    case case "mercury": 
        info = "The planet closest to the sun.";
        break;
    case "venus": 
        ...
}
And, again, don't forget the breaks.

************

EDIT: See? If I didn't write so much, I wouldn't be last to the party. <grin/>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote