switch语句用来定义多分支条件语句,语法如下:switch(表达式){case 值1:执行体1;break;case 值2:执行体2;break;...default:默认执行体;break; //default语句中break可有可无。}注:每个case语句代码块中必须加break,不加的话,它就会继续往下执行,就不能起到分支控制的效果了
var score = prompt("请输入分数");switch (+score) {case 100:console.log("满分");break;case 90:console.log("优");break;case 80:console.log("良");break;default:console.log("重修")}
