switch (true) {
case !(age >= 0 && age <= 120):
alert("无法判断");
break;
case 0 <= age && age <= 10:
alert("儿童");
break;
case 10 < age && age <= 20:
alert("青少年");
break;
case 20 < age && age <= 40:
alert("青年");
break;
case 40 < age && age <= 60:
alert("中年");
break;
default:
alert("老年");
break;
}
switch (Math.ceil(age/10)):
{
case 0:
case 1:
alert("儿童");
break;
case 2:
alert("青少年");
break;
case 3:
case 4:
alert("青年");
break;
case 5:
case 6:
alert("中年");
break;
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
alert("老年");
break;
default:
alert("无法判断");
break;
}未经测试,仅提供思路。