Reputation: 129
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
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
Reputation: 348
Try this:
if ( (300 =< x1 && x1 =< 800) && (10 =< y1 && y1 =< 30) ) { ... }
Upvotes: 1
Reputation: 12039
You can try this
if ((x1 >= 300 && x1 <= 800) && (y1 >= 10 && y1 <= 30)) {
//....
}
Upvotes: 2