In the front-end domain, a lot of times, a simple function can have a lot of different implementations, today take the weeks of different scripting methods as an example, hoping to inspire children's shoes more ideas.
1. Use 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