0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[js]誕生日から日本で一般的な星座を割り出す

Posted at
function getZodiacNumber(birthMonth, birthDay) {
  const zodiacSigns = [
    { name: '魚座', number: 12, start: [2, 19], end: [3, 20] },
    { name: '牡羊座', number: 1, start: [3, 21], end: [4, 19] },
    { name: '牡牛座', number: 2, start: [4, 20], end: [5, 20] },
    { name: '双子座', number: 3, start: [5, 21], end: [6, 21] },
    { name: '蟹座', number: 4, start: [6, 22], end: [7, 22] },
    { name: '獅子座', number: 5, start: [7, 23], end: [8, 22] },
    { name: '乙女座', number: 6, start: [8, 23], end: [9, 22] },
    { name: '天秤座', number: 7, start: [9, 23], end: [10, 23] },
    { name: '蠍座', number: 8, start: [10, 24], end: [11, 22] },
    { name: '射手座', number: 9, start: [11, 23], end: [12, 21] },
    { name: '山羊座', number: 10, start: [12, 22], end: [1, 19] },
    { name: '水瓶座', number: 11, start: [1, 20], end: [2, 18] }
  ];

  for (const zodiac of zodiacSigns) {
    const [startMonth, startDay] = zodiac.start;
    const [endMonth, endDay] = zodiac.end;

    if (
      (birthMonth === startMonth && birthDay >= startDay) ||
      (birthMonth === endMonth && birthDay <= endDay) ||
      (birthMonth > startMonth && birthMonth < endMonth)
    ) {
      return zodiac.number;
    }
  }

  return null; // 該当しない場合
}

// 例: 誕生日が4月15日なら牡羊座(1)
const birthMonth = 4;
const birthDay = 15;
const zodiacNumber = getZodiacNumber(birthMonth, birthDay);
console.log(`星座番号: ${zodiacNumber}`);
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?