Starr Duskk
asked on
Javascript AND syntax
I need to know how to turn this javascript two liner into a oneliner.
I don't want the if/else. Instead I want to combine the statements in the code below. I don't know the syntax.
if majorversion <10 AND minorversion < 1 then
do this
thanks!
I don't want the if/else. Instead I want to combine the statements in the code below. I don't know the syntax.
if majorversion <10 AND minorversion < 1 then
do this
if ((version['major'] < 10)) {
pageLoc = PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);
}
else if ((version['minor'] < 1)) {
pageLoc = PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);
}
thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is a demo using the same structure of a comparison and then assigning to a final variable: http://jsbin.com/IfuFaWE/1/edit
var version = [];
version.major = Math.random()*20;
version.minor = Math.random()*2;
pageLoc = (version.major < 10) ? "Major less than 10: " + version.major : ((version.minor < 1) ? "Minor less that 1: " + version.minor : "Didn't match either - major: " + version.major + " minor: " + version.minor );
console.log(pageLoc);
Why do you need the if / else when the ultimate result is the same?
pageLoc = PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);
ASKER
I think this is what I actually need:
is that == right?
if (version['major'] == 10 && version['minor'] < 1)
is that == right?
ASKER
>>Why do you need the if / else when the ultimate result is the same?
I didn't provide my final else statement. You only need to see what I need assistance with.
I didn't provide my final else statement. You only need to see what I need assistance with.
ASKER
btw, I have an if/else if/else so I need to keep the structure Gary suggested.
ASKER
Here's what I'm going for. To see if they are using a version less than 10.1:
if ((version['major'] < 10)) {
pageLoc = PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);
}
else if (version['major'] == 10 && version['minor'] < 1) {
pageLoc = PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);
}
else {
pageLoc = PageMethods.GetSuccessPath(location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);
}
Did you see my comment above? That is an if else if else
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If this is just about getting anything lower than version 10.1 then yes you're on the right track... sorry my thinking was you wanted to condense the code.
The logic you've got is right: though why wouldn't you just go with this:
That tests for less than 10.1 and everything else
The logic you've got is right: though why wouldn't you just go with this:
if (version['major'] == 10 && version['minor'] < 1) {
pageLoc = PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);
}
else {
pageLoc = PageMethods.GetSuccessPath(location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);
}
That tests for less than 10.1 and everything else
ASKER
thanks!
Thanks @BobCSD - Can you post the code you ended up using, cheers,
Can't test this exactly but I know it works with simple substitution:
Open in new window