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


                    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);
                    }

Open in new window


thanks!
LVL 2
Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
You can't because you are testing against two different conditions.

Edit
Ermm same vars use || (means OR - either condition), && means AND i.e. both conditions

if (version['major'] < 10 || version['minor'] < 1) {
         pageLoc = PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);
                    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobOwner (Aidellio)Commented:
You can do this with () ? :; the () is the if statement, the ? designates the THEN and the : designates the ELSE.  to combine the ELSE if you nest the next () ? : in the ELSE of the first :) confusing?? :P

Can't test this exactly but I know it works with simple substitution:

pageLoc = (version['major'] < 10) ? PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure) : ((version['minor'] < 1)?PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure) : 0  );

Open in new window

0
RobOwner (Aidellio)Commented:
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);

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Julian HansenCommented:
Why do you need the if / else when the ultimate result is the same?

pageLoc = PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure);

Open in new window

0
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I think this is what I actually need:
if (version['major'] == 10 && version['minor'] < 1) 

Open in new window


is that == right?
0
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
>>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.
0
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
btw, I have an if/else if/else so I need to keep the structure Gary suggested.
0
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
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);
                    }

Open in new window

0
RobOwner (Aidellio)Commented:
Did you see my comment above? That is an if else if else
0
RobOwner (Aidellio)Commented:
This is what you've got in your last post as one line:

pageLoc = (version['major'] < 10) ? PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure) : ( (version['major'] == 10 && version['minor'] < 1) ? PageMethods.GetFailurePath(ver,location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure) : PageMethods.GetSuccessPath(location.href, location.pathname, OnGetMessageSuccess, OnGetMessageFailure));

Open in new window

0
RobOwner (Aidellio)Commented:
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:

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);
                    }

Open in new window


That tests for less than 10.1 and everything else
0
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
thanks!
0
RobOwner (Aidellio)Commented:
Thanks @BobCSD - Can you post the code you ended up using, cheers,
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.