SasukeRinnegan
SasukeRinnegan

Reputation: 129

Basic JS operators for condition

Let's say I have this code:

if (x1 >= 300 && y1 >= 10) { ... }

I want to say, if x1 is greater than or equal to 300 AND is smaller than or equal to 800, as well as if y1 is greater than or equal to 10 AND is smaller than or equal to 30. How can I write that?

Upvotes: 4

Views: 71

Answers (3)

Birlla
Birlla

Reputation: 1840

if((x1 >= 300 && x1 <= 800) && (y1 >= 10 && y1 <= 30))
{
   //do your stuff here
}

You could write a between function yourself

function between(x, min, max) {
  return x >= min && x <= max;
}
// ...
if (between(x, 300, 800)) {
   // something
 }

Upvotes: -2

Οurous
Οurous

Reputation: 348

Try this:

if ( (300 =< x1 && x1 =< 800) && (10 =< y1 && y1 =< 30) ) { ... }

Upvotes: 1

MH2K9
MH2K9

Reputation: 12039

You can try this

if ((x1 >= 300 && x1 <= 800) && (y1 >= 10 && y1 <= 30)) {
    //....
}

Upvotes: 2

Related Questions