-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzodiac.js
41 lines (39 loc) · 1.61 KB
/
zodiac.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
function getHoroscope(birthDate) {
const day = birthDate.getDate();
const month = birthDate.getMonth() + 1;
// Determine the Zodiac sign based on the birth date
if ((month === 3 && day >= 21) || (month === 4 && day <= 19))
return "Aries";
else if ((month === 4 && day >= 20) || (month === 5 && day <= 20))
return "Taurus";
else if ((month === 5 && day >= 21) || (month === 6 && day <= 20))
return "Gemini";
else if ((month === 6 && day >= 21) || (month === 7 && day <= 22))
return "Cancer";
else if ((month === 7 && day >= 23) || (month === 8 && day <= 22))
return "Leo";
else if ((month === 8 && day >= 23) || (month === 9 && day <= 22))
return "Virgo";
else if ((month === 9 && day >= 23) || (month === 10 && day <= 22))
return "Libra";
else if ((month === 10 && day >= 23) || (month === 11 && day <= 21))
return "Scorpio";
else if ((month === 11 && day >= 22) || (month === 12 && day <= 21))
return "Sagittarius";
else if ((month === 12 && day >= 22) || (month === 1 && day <= 19))
return "Capricorn";
else if ((month === 1 && day >= 20) || (month === 2 && day <= 18))
return "Aquarius";
else if ((month === 2 && day >= 19) || (month === 3 && day <= 20))
return "Pisces";
else
throw new Error("Invalid birth date.");
}
// Usage example
const birthDate = new Date("1990-08-15"); // Replace with the desired birth date
try {
const zodiacSign = getHoroscope(birthDate);
console.log(`Zodiac sign: ${zodiacSign}`);
} catch (error) {
console.error(error.message);
}