<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习1</title>
<script type="text/javascript">
/*
* 对于成绩大于等于60分的,输出'合格'。低于60分的,输出'不合格'
*/
var score = Number(prompt('成绩'));
switch(parseInt(score/60)){
case 1:
alert('合格');
break;
case 0:
alert('不合格');
break;
}
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习2</title>
<script type="text/javascript">
/*
* 从键盘接收整数参数,如果该数为1-7,打印对应的星期,否则打印非法参数。
*/
var num = Number(prompt('number'));
switch(num){
case 1:
alert('sunday');
break;
case 2:
alert('monday');
break;
case 3:
alert('tuesday');
break;
case 4:
alert('Wednesday');
break;
case 5:
alert('Thursday');
break;
case 6:
alert('Friday');
break;
case 7:
alert('Saturday');
break;
default:
alert('erro');
break;
}
</script>
<body>
</body>
</html>
网友评论