Created
December 24, 2021 15:08
-
-
Save antonlukin/ff7be03762aa18931a5b11fc14bfb782 to your computer and use it in GitHub Desktop.
Get Zodiac sign by date
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
const date = new Date(); | |
// as on 2 April 2021 | |
const findSign = (date) => { | |
const days = [21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22]; | |
const signs = ["Aquarius", "Pisces", "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn"]; | |
let month = date.getMonth(); | |
let day = date.getDate(); | |
if(month == 0 && day <= 20){ | |
month = 11; | |
}else if(day < days[month]){ | |
month--; | |
}; | |
return signs[month]; | |
}; | |
console.log(findSign(date)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment