forked from cruzw/horoscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
horoscope.js
122 lines (118 loc) · 2.9 KB
/
horoscope.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Get Astrological Sign from Birthday MONTH and Birthday DAY
* @throws {Error} if month is not between 1-12
* @throws {Error} if day is not between 1-31
* @param {number} month birth month
* @param {number} day birth day
* @returns {string} Astrological Sign
*/
exports.getSign = function (month, day) {
'use strict';
if (month < 1 || month > 12) {
throw new Error("month needs to be between 1-12");
} else if (day < 1 || day > 31) {
throw new Error("check that day isn't zero, negative, or greater than 31");
} else if (month <= 6 && month > 0) { //months: Jan, Feb, March, Apr, May, June
switch (month) {
case 1: //January
if (day <= 19) {
return "Capricorn";
} else {
return "Aquarius";
}
case 2: //February
if (day <= 19) {
return "Aquarius";
} else {
return "Pisces";
}
case 3: //March
if (day <= 20) {
return "Pisces";
} else {
return "Aries";
}
case 4: //April
if (day <= 20) {
return "Aries";
} else {
return "Taurus";
}
case 5: //May
if (day <= 20) {
return "Taurus";
} else {
return "Gemini";
}
case 6: //June
if (day <= 20) {
return "Gemini";
} else {
return "Cancer";
}
}
} else if (month > 6) { //months: July, Aug, Sept, Oct, Nov, Dec
switch (month) {
case 7: //July
if (day <= 22) {
return "Cancer";
} else {
return "Leo";
}
case 8: //August
if (day <= 22) {
return "Leo";
} else {
return "Virgo";
}
case 9: //September
if (day <= 22) {
return "Virgo";
} else {
return "Libra";
}
case 10: //October
if (day <= 22) {
return "Libra";
} else {
return "Scorpio";
}
case 11: //November
if (day <= 21) {
return "Scorpio";
} else {
return "Sagittarius";
}
case 12: //December
if (day <= 21) {
return "Sagittarius";
} else {
return "Capricorn";
}
}
}
};
/**
* Gets Zodiac sign from birth year
* @param {number} year birth year
* @returns {string} Zodiac Animal
*/
// Should also account for day of chinese new year (since it changes but is in february)
exports.getZodiac = function (year) {
'use strict';
remainderAnimals = {
0: "Monkey",
1: "Rooster",
2: "Dog",
3: "Pig",
4: "Rat",
5: "Ox",
6: "Tiger",
7: "Rabbit",
8: "Dragon",
9: "Snake",
10: "Horse",
11: "Goat"
};
return remainderAnimals[year % 12];
};