找出你那一年的星座属性

根据阳历出生日期查询你的星座和运势。




javascript
const form = document.querySelector(‘form’);
const result = document.getElementById(‘result’);

form.addEventListener(‘submit’, (event) => {
event.preventDefault();
const birthDate = new Date(event.target.querySelector(‘input[name=”birth_date”]’).value);
const month = birthDate.getMonth();
const day= birthDate.getDate();
let constellation = “”;

// 判断星座
if (month === 0 && day >= 20 || month === 1 && day <= 18) {
constellation = “水瓶座”;
} else if (month === 1 && day >= 19 || month === 2 && day <= 20) {
constellation = “双鱼座”;
} else if (month === 2 && day >= 21 || month === 3 && day <= 20) {
constellation = “白羊座”;
} else if (month === 3 && day >= 21 || month === 4 && day <= 20) {
constellation = “金牛座”;
} else if (month === 4 && day >= 21 || month === 5 && day <= 21) {
constellation = “双子座”;
} else if (month === 5 && day >= 22 || month === 6 && day <= 21) {
constellation = “巨蟹座”;
} else if (month === 6&& day >= 22 || month === 7 && day <= 22) {
constellation = “狮子座”;
} else if (month === 7 && day >= 23 || month === 8 && day <= 23) {
constellation = “处女座”;
} else if (month === 8 && day >= 24 || month === 9 && day <= 23) {
constellation = “天秤座”;
} else if (month === 9 && day >= 24 || month === 10 && day <= 22) {
constellation = “天蝎座”;
} else if (month === 10 && day >= 23 || month === 11 && day <= 21) {
constellation = “射手座”;
} else if (month === 11 && day >= 22 || month === 12 && day <= 21) {
constellation = “摩羯座”;
}

// 显示结果
result.innerHTML = `

你的星座是:${constellation}

`;
});

By botpp

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注