Switch cases are usually like
Monday:
Tuesday:
Wednesday:
etc.
I would like to use ranges.
from 1-12:
from 13-19:
from 20-21:
from 22-30:
Is it possible? I’m using javascript/jquery by the way.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
you could try abusing the switch fall through behaviour
which is very verbose
or you could try this
this gets you the behaviour you would like. The reason i return
!xin the else of checkRange is to prevent the problem of when you passundefinedinto the switch statement. if your function returnsundefined(as jdk’s example does) and you passundefinedinto the switch, then the first case will be executed.!xis guaranteed to not equalxunder any test of equality, which is how the switch statement chooses which case to execute.