web前端笔记

switch 语句

2018-07-09  本文已影响0人  小姨家错对门
var now = new Date();
var day = now.getDay();
var week;
switch(day){
    case 1:
      week = "星期一";
    break;
    case 2:
      week = "星期二";
    break;
    case 3:
      week = "星期三";
    break;
    case 4:
      week = "星期四";
    break;
    case 5:
      week = "星期五";
    break;
    case 6:
      week = "星期六";
    break;
    default:
      week = "星期日";
    break;
}
console.log('今天是'+week);

结果:
今天是星期一

就是这么简单!
上一篇 下一篇

猜你喜欢

热点阅读