-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconSwitch.js
More file actions
63 lines (57 loc) · 1.65 KB
/
conSwitch.js
File metadata and controls
63 lines (57 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Training JS #8: Conditional statement--switch
// Task
// Complete function howManydays, function accept 1 parameters:month, means the month of year, different month has different days (refer to the following table), return a number that how many days in this month(month is always greater than 0, less than or equal to 12).
// +---------------+-------------+
// | month | days |
// +---------------+-------------+
// |1,3,5,7,8,10,12| 31 |
// +---------------+-------------+
// |4,6,9,11 | 30 |
// +---------------+-------------+
// |2 | 28 | (Do not consider the leap year)
// +---------------+-------------+
// little tips: Use default for most of the cases can reduce your work.
// When you have finished the work, click "Run Tests" to see if your code is working properly.
// In the end, click "Submit" to submit your code pass this kata.
function howManydays(month){
var days;
switch (month){
case 1:
return days= 31
break;
case 2:
return days = 28
break;
case 3:
return days = 31
break;
case 4:
return days = 30;
break;
case 5:
return days = 31;
break;
case 6:
return days = 30;
break;
case 7:
return days = 31;
break;
case 8:
return days = 31;
break;
case 9:
return days = 30;
break;
case 10:
return days = 31;
break;
case 11:
return days = 30;
break;
case 12:
return days = 31;
break;
}
return days;
}