Is there a way in Javascript to compare one integer with another through switch case structures without using if statements?
E.g.
switch(integer) {
As stated in my comment, you can't do that. However, you could define an inRange
function:
function inRange(x, min, max) {
return min <= x && x <= max;
}
and use it together with if - else if
. That should make it quite easy to read:
if(inRange(integer, 1, 10)) {
}
else if(inRange(integer, 11, 20)) {
}
//...