2

i try to user switch (range of number) but it seems not work? can you help me check it where is the problem?

JSFIDDLE

case (tot>10 && tot<110):
         $total.html(tot);
         $risk.html('小');
break;

case (tot>110 && tot<310):
         $total.html(tot);
         $risk.html('大');
Pointy
  • 405,095
  • 59
  • 585
  • 614
hukuto7750
  • 141
  • 1
  • 1
  • 10
  • Its not possible in the way you have illustrated, check this out for more information http://stackoverflow.com/questions/1616724/jquery-using-ranges-in-switch-cases – RossBille Jul 23 '14 at 01:17
  • This works in JavaScript because the language spec is such that duplicate case expression values are not a problem. In some languages, that's not OK. – Pointy Jul 23 '14 at 01:27

1 Answers1

4

You can use just as suggested here

switch (true) {
    case (tot>10 && tot<110):
        $total.html(tot);
        $risk.html('小');
        break;
    case (tot>110 && tot<310):
        $total.html(tot);
        $risk.html('大');
        break;
 }
Community
  • 1
  • 1
Nizam
  • 4,569
  • 3
  • 43
  • 60