Hey, I don't understand how the switch statement works, I think I am doing everything right but am obviously missing something because I just can't get the damn thing to work. Here is what I have so far: var state = prompt("What state are you in?", ""); switch(state.toUppercase()) { case "CA" : alert("You live in CA"); break; case "HI" : alert("You live in HI"); break; default : alert("Heck know's where you live"); break; } Code (markup): It just alerts me the default text even if I type in one of those states. Any help is much appreciated. Thanks!
Replace switch(state.toUppercase()) Code (markup): with: switch(state.toUpperCase()) Code (markup): Works for me.
Oh whoops, needed to make that to upper case but I noticed it don't work in IE but works perfect in FireFox, stupid IE. Thanks anyway, I just needed to check I had the right idea about switch statements!
I.E. runs the corrected code as it should. Your original code would have generated an error in the console. http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:switch