Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to OR statement

Tags:

javascript

What I am trying to do is redirect countries, based on country code with the script below. The code below does not work. Doing some research I found I have to use an or statement or at least that's what I think I need, but my question is there an easier way then an or statement? As you can see there are a lot countries I am checking for.

<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">

var country= geoip_country_code();

if(country = "UK","CA","DE","DK","FR","AU","SE","CH","NL","IT","BE","AT","ES","NO","IE","FI","GB","US")      
{
window.location.href='http://www.google.com'; 
}
else   
{
window.location.href='http://www.yahoo.com'; 
}
</script>
like image 812
user2716614 Avatar asked Oct 08 '13 04:10

user2716614


People also ask

What are alternative statements?

An alternative is elaborated by elaborating its statements. If one statement fails, then the alternative fails. If all statements succeed, then the alternative succeeds.

What are some examples of alternative?

Alternative is defined as something that does not conform to existing or mainstream standards. Acupuncture is an example of an alternative medical treatment. The definition of alternative is something that is a possible selection. The route you decided to take is an example of an alternative route.

What is an example of a alternative sentence?

Alternative sentences are sometimes offered and include different combinations of the following: a suspended sentence, probation, fines, restitution, community service and deferred adjudication/pretrial diversion.

What is alternative word?

Some common synonyms of alternative are choice, election, option, preference, and selection. While all these words mean "the act or opportunity of choosing or the thing chosen," alternative implies a need to choose one and reject another possibility.


1 Answers

You should be able to do it like this:

var countryCodes = ["UK","CA","DE","DK","FR","AU","SE","CH","NL","IT","BE","AT","ES","NO","IE","FI","GB","US"];
var country= geoip_country_code();
if (countryCodes.indexOf(country) !== -1)
{
    ...
}
like image 148
Ben S. Avatar answered Oct 17 '22 21:10

Ben S.