The first way to write
var str = "" ;
var week = new Date().getDay();
if (week == 0) {
str = "Today is Sunday";
} else if (week == 1) {
str = "Today is Monday";
} else if (week == 2) {
str = "Today is Tuesday";
} else if (week == 3) {
str = "Today is Wednesday";
} else if (week == 4) {
str = "Today is Thursday";
} else if (week == 5) {
str = "Today is Friday";
} else if (week == 6) {
str = "Today is Saturday"; > alert(str);
The second writing method
var str = "Today is week";
var week = new Date().getDay();
switch (week) {
case 0 :
str = "日";
break;
case 1 :
str = "一";
break;
case 2:
str = "二";
break; str = "四"; :
str = "five";
break;
case 6 :
str = "six";
break;
}
alert(str);
The third way of writing
Copy code
The code is as follows:
Copy the code
The code is as follows:
var str = "Today is week" "Day one, two, three, four, five, six".charAt(new Date().getDay( ));alert(str);