条件判断语句有:if{}else{}
switch(){case}
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<title>if语句练习</title>
<script type="text/javascript">
var num1 = prompt("请输入第一个数:");
var num2 = prompt("请输入第二个数:");
var num3 = prompt("请输入第三个数:");
if(num1 < num2 && num1 < num3 ){
if(num2 < num3){
alert(num1+","+num2+","+num3);
}else{
alert(num1+","+num3+","+num2);
}
}else if(num2 < num1 && num2 < num3){
if(num1<num3){
alert(num2+","+num1+","+num3);
}else{
alert(num2+","+num3+","+num1);
}
}else if(num3 < num1 && num3 < num2){
if(num1<num2){
alert(num3+","+num1+","+num2);
}else{
alert(num3+","+num2+","+num1);
}
}
</script>
</head>
</html>
注意语法:if(){ } else if(){ } else{ }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>switch练习</title>
<script type="text/javascript">
/* var score =55;
switch(parseInt(score/10)){
case 10:
case 9:
case 8:
case 7:
case 6:
console.log("合格");
break;
default:
console.log("不合格");
break;
}
*/
/* var score =60;
switch(true){
case score>=60:
console.log("合格");
break;
default:
console.log("不合格");
break;
}
*/
var num = prompt("请输入数字1-7:");
switch(parseInt(num)){
case 1:
console.log("星期一");
break;
case 2:
console.log("星期二");
break;
case 3:
console.log("星期三");
break;
case 4:
console.log("星期四");
break;
case 5:
console.log("星期五");
break;
case 6:
console.log("星期六");
break;
case 7:
console.log("星期日");
break;
default:
console.log("非法数字");
}
</script>
</head>
<body>
</body>
</html>
注意:switch{case break; default}