You can make interesting kludges. For example, to test a number against a range using a JavaScript switch, you could write a custom function. Basically, the function test a gives the value n and returns it if it is in range. Otherwise, an undefined or other dummy value is returned.
<script> // Custom Checking Function.. function inRangeInclusive(start, end, value) { if (value <= end && value >= start) return value; // return given value return undefined; } // CODE TO TEST FUNCTION var num = 3; switch(num) { case undefined: //do something with this 'special' value returned by the inRangeInclusive(..) fn break; case inRangeInclusive(1, 10, num): alert('in range'); break; default: alert('not in range'); break; } </script>
This works in Google Chrome. I have not tested other browsers.
John k
source share