Last active
October 17, 2023 04:39
-
-
Save kladov/5080233 to your computer and use it in GitHub Desktop.
Zodiac sign (javascript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return zodiac sugn by month and day | |
* | |
* @param day | |
* @param month | |
* @return {string} name of zodiac sign | |
*/ | |
function getZodiacSign(day, month) { | |
var zodiacSigns = { | |
'capricorn':'Козерог', | |
'aquarius':'Водолей', | |
'pisces':'Рыбы', | |
'aries':'Овен', | |
'taurus':'Телец', | |
'gemini':'Близнецы', | |
'cancer':'Рак', | |
'leo':'Лев', | |
'virgo':'Девы', | |
'libra':'Весы', | |
'scorpio':'Скорпион', | |
'sagittarius':'Стрелец' | |
} | |
if((month == 1 && day <= 20) || (month == 12 && day >=22)) { | |
return zodiacSigns.capricorn; | |
} else if ((month == 1 && day >= 21) || (month == 2 && day <= 18)) { | |
return zodiacSigns.aquarius; | |
} else if((month == 2 && day >= 19) || (month == 3 && day <= 20)) { | |
return zodiacSigns.pisces; | |
} else if((month == 3 && day >= 21) || (month == 4 && day <= 20)) { | |
return zodiacSigns.aries; | |
} else if((month == 4 && day >= 21) || (month == 5 && day <= 20)) { | |
return zodiacSigns.taurus; | |
} else if((month == 5 && day >= 21) || (month == 6 && day <= 20)) { | |
return zodiacSigns.gemini; | |
} else if((month == 6 && day >= 22) || (month == 7 && day <= 22)) { | |
return zodiacSigns.cancer; | |
} else if((month == 7 && day >= 23) || (month == 8 && day <= 23)) { | |
return zodiacSigns.leo; | |
} else if((month == 8 && day >= 24) || (month == 9 && day <= 23)) { | |
return zodiacSigns.virgo; | |
} else if((month == 9 && day >= 24) || (month == 10 && day <= 23)) { | |
return zodiacSigns.libra; | |
} else if((month == 10 && day >= 24) || (month == 11 && day <= 22)) { | |
return zodiacSigns.scorpio; | |
} else if((month == 11 && day >= 23) || (month == 12 && day <= 21)) { | |
return zodiacSigns.sagittarius; | |
} | |
} |
according to wikipedia, most of these dates are off by one https://en.wikipedia.org/wiki/Astrological_sign
Can I get the full code, please?
Thanks!
here's my version using Wikipedia dates, but unsure about August 23
https://github.com/tindoductran/zodiac/blob/master/getZodiac.html
UPDATE: getZodiac2() is even better uses array logic instead of multiple if/else's https://github.com/tindoductran/zodiac/blob/master/getZodiac2.html
I created this snippet to get the zodiac sign using Intl.DateTimeFormat : https://www.linkedin.com/pulse/get-zodiac-sign-current-date-javascript-mohamed-safouan-besrour/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kladov this code does not cover the case of
month === 6 && day === 21