const idCard = ’你的身份证‘;
//出生年月
let birthDay = idCard.substr(6,14);
let birthDay = idCard.substr(6, 4) + "-" + idCard.substr(10, 2) + "-" + idCard.substr(12, 2); // - 组装
//性别
let genderCode = idCard.charAt(16);
let sex;
if (parseInt(genderCode) % 2 == 0) {
sex = '女';
}else{
sex = '男';
}
//星座
const birthMonth = parseInt(idCard.substring(10, 12));
const birthDay = parseInt(idCard.substring(12,14));
let constellationName;
const constellations = [
{ name: '水瓶座', start: { month: 1, day: 20 }, end: { month: 2, day: 18 } },
{ name: '双鱼座', start: { month: 2, day: 19 }, end: { month: 3, day: 20 } },
{ name: '白羊座', start: { month: 3, day: 21 }, end: { month: 4, day: 19 } },
{ name: '金牛座', start: { month: 4, day: 20 }, end: { month: 5, day: 20 } },
{ name: '双子座', start: { month: 5, day: 21 }, end: { month: 6, day: 21 } },
{ name: '巨蟹座', start: { month: 6, day: 22 }, end: { month: 7, day: 22 } },
{ name: '狮子座', start: { month: 7, day: 23 }, end: { month: 8, day: 22 } },
{ name: '处女座', start: { month: 8, day: 23 }, end: { month: 9, day: 22 } },
{ name: '天秤座', start: { month: 9, day: 23 }, end: { month: 10, day: 23 } },
{ name: '天蝎座', start: { month: 10, day: 24 }, end: { month: 11, day: 22 } },
{ name: '射手座', start: { month: 11, day: 23 }, end: { month: 12, day: 21 } },
{ name: '摩羯座', start: { month: 12, day: 22 }, end: { month: 1, day: 19 } },
];
constellations.forEach(constellation => {
if (birthMonth === constellation.start.month && birthDay >= constellation.start.day) {
constellationName = constellation.name;
} else if (birthMonth === constellation.end.month && birthDay <= constellation.end.day) {
constellationName = constellation.name;
}
});
console.log(constellationName)