This article introduces four JS code writing methods for today's day of the week. If you need them, refer to the first method.
The Code is as follows:
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 ";
}
Name = "code" class = "javascript"> alert (str );
Second statement
The Code is as follows:
Var str = "Today is the week ";
Var week = new Date (). getDay ();
Switch (week ){
Case 0:
Str + = "day ";
Break;
Case 1:
Str + = "1 ";
Break;
Case 2:
Str + = "2 ";
Break;
Case 3:
Str + = "3 ";
Break;
Case 4:
Str + = "4 ";
Break;
Case 5:
Str + = "5 ";
Break;
Case 6:
Str + = "6 ";
Break;
}
Alert (str );
Third Writing Method
The Code is as follows:
Var a = new Array ("day", "one", "two", "three", "four", "five", "Six ");
Var week = new Date (). getDay ();
Var str = "Today is the week" + a [week];
Alert (str );
Fourth Writing Method
The Code is as follows:
Var str = "Today is the week" + "May 25, 1234". charAt (new Date (). getDay (); alert (str );