"Day of the Week" different script notation

Source: Internet
Author: User
Tags case statement switch case

1. Using the IF statement

varstr = "";varWeek =NewDate (). 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";}

2. Use the switch Case statement

varSTR1 = "Today is the Week";varWeek =NewDate (). GetDay ();Switch(week) { Case0: str1+ = "Day";  Break;  Case1: str1+ = "One";  Break;  Case2: str1+ = "Two";  Break;  Case3: str1+ = "three";  Break;  Case4: str1+ = "Four";  Break;  Case5: str1+ = "Five";  Break;  Case6: str1+ = "Six";  Break;} alert (str1);

3, artifact, a word to solve

var str = "Today is the Week" + "Day 123456". CharAt (new  date (). GetDay ()); alert (str);

"Day of the Week" different script notation

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.