How to check if args[1] is in a range of numbers
Solution 1:
Unlike Python, you cannot do 2 comparisons in the same "block" of code.
The code 1 < 2 < 3
is actually doing (1 < 2) < 3
which actually works out as true < 3
and as JS uses false=0, true=1, you are now checking if 1 < 3, not if 2 is.
So, in your case, it will always return true as either false(0) OR true(1) will be less than 10.
Just change it to -10 < parseInt(args[1]) && parseInt(args[1]) < 10
with an undefined/length check before it.
For example:
if (args.length >= 2 && -10 < parseInt(args[1]) && parseInt(args[1]) < 10) {
message.channel.send("yes");
} else {
message.channel.send("no");
}
Solution 2:
JS won't throw any error of IndexOutOfRange as other languages like C#, Java.
It'll return undefined
instead.
Please below snippet for how it may happen.
If your logic is to check a value in between -10 and 10, you have to change a little bit with an &
operator.
Cheers.