Today is the day of the week in four JS Code Writing _ javascript skills

Source: Internet
Author: User
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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.