34.2 switch练习2

<!DOCTYPE html>
<html>
     <head>
         <meta charset=”UTF-8″>
         <title>switch练习2</title>
         <script type=”text/javascript”>
             /*
              * 从键盘接收整数参数,如果该数为1-7,打印对应的星期,否则打印非法参数。
              */
             var week=prompt(“请输入今天是一周的第几天(数字):”);
            
             //输入的是字符串,需要先转换为数字或者直接引用字符串
             week=parseInt(week);
             switch(week){
                 case 1:
                     alert(“星期一”);
                     break;
                
                 case 2:
                     alert(“星期二”);
                     break;
                
                 case 3:
                     alert(“星期三”);
                     break;
                
                 case 4:
                     alert(“星期四”);
                     break;
                
                 case 5:
                     alert(“星期五”);
                     break;
                
                 case 6:
                     alert(“星期六”);
                     break;
                
                 case 7:
                     alert(“星期日”);
                     break;
                
                 default:
                     alert(“请注意:非法输入”);
                     break;
                
             }
         </script>
     <body>
     </body>
</html>

打赏

发布者

张 大鹏

北京理想国惠玩科技有限公司CEO

发表评论

电子邮件地址不会被公开。 必填项已用*标注