Today is the day of the Week 4 kinds of JS code _javascript Tips

Source: Internet
Author: User
The first form of writing

Copy Code code 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);</pre>

The second one
Copy Code code as follows:

var str = "Today is Week";
var week = new Date (). Getday ();
Switch (week) {
Case 0:
str = "Day";
Break
Case 1:
str = "one";
Break
Case 2:
STR + + "II";
Break
Case 3:
STR + + "three";
Break
Case 4:
STR + + "four";
Break
Case 5:
STR + + "V";
Break
Case 6:
STR + + "VI";
Break
}
alert (str);

The third way of writing
Copy Code code as follows:

var a = new Array ("Day", "one", "two", "three", "four", "five", "six");
var week = new Date (). Getday ();
var str = "Today is Week" + A[week];
alert (str);

The fourth way of writing
Copy Code code as follows:

var str = "Today is the Week" + "Day 123456". CharAt (New Date (). Getday ()); alert (str);

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.