Possible Duplicate:
Alternative to a million IF statements
I am new to programming so I know very little. (Sorry for posting a newbie question)
Here is my question.
I have used "if, else" statement to redirect users depending on their country like this.
if (country == 'US') {
window.location=us
}
else {
if (country == 'GR') {
window.location=gr
}
else {
// (repeated this for 5 times/5 different countries)
}
}
Well, now, I need to redirect visitors to their states (i.e., California, Arizona, etc.).
The problem is, if I keep using if/else statement, I know I have to repeat this for 50 times and the javascript code will end up looking ridiculous.
I know there is a better way to do this.
Can anyone show how to replace multiple if/else statement into an array? Array should be used in a situation like this? Am I correct?
If I am wrong, can you please correct me & show me what other statement should be used instead?
Thank you & once again, I apologize for putting up such a newbie question.