我正在尝试创建一个 JS 函数,将今天的日期与一组生日进行比较,并在今天是某人的生日时提醒用户。以下是我的代码;
const birthdays = [
{ name: "Bob Marley", birthmonth: "06", birthdate: "01" },
{ name: "Peter Pan", birthmonth: "08", birthdate: "04" },
];
const today = new Date();
if (
today.getDate() === birthdays.birthdate &&
today.getMonth() === birthdays.birthmonth
) {
alert("Happy Birthday!" + birthdays.name);
} else {
alert("Have a nice day!");
}