Adam Lambert
Adam Lambert

Reputation: 1421

javascript, combining AND, OR in an if starement

I would like my code to be able to do the following:

IF (value1 is less than -1 AND variable2 does not equal either 6 or 5) then...

So far I could get a single if and to work as follows;

if ( (value < -1 && (day !== 6)) )  sendEmail(value)

but as soon as I add in the second or it falls over. What am I doing wrong? I have tried it in a few different ways but below are a couple of examples that did not work.

if ( (value < -1 && (day !== 6 || 5)) )  sendEmail(value)

if ( (value < -1 && (day !== 6 || day !== 5)) )  sendEmail(value)

Upvotes: 0

Views: 57

Answers (2)

Sumner Evans
Sumner Evans

Reputation: 9157

Think about your logic. Basically what you want is:

IF (value1 is less than -1 AND variable2 is not equal to 6 AND variable2 is not equal to 5)

Therefore your if statement can be written as:

if (value < -1 && day != 6 && day != 5) sendEmail(value);

Upvotes: 1

ViRuSTriNiTy
ViRuSTriNiTy

Reputation: 5155

if(value < -1 && day !== 6 && day !== 5)  sendEmail(value)

should do the trick.

Upvotes: 0

Related Questions