Skip to content

Instantly share code, notes, and snippets.

@antonlukin
Created December 24, 2021 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonlukin/ff7be03762aa18931a5b11fc14bfb782 to your computer and use it in GitHub Desktop.
Save antonlukin/ff7be03762aa18931a5b11fc14bfb782 to your computer and use it in GitHub Desktop.
Get Zodiac sign by date
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