I am looking to create a simple script for displaying birthday and nameday congratulations. The objective is to:
- Retrieve the current day.
- Store employee data in an array.
- If an employee's name matches the nameday variable, display a congratulatory message for all employees celebrating namedays on that day.
- Repeat the same process for birthdays where multiple people can celebrate their birthdays on the same day.
- If a name or date does not match our employee list, take no action.
This is what I have written so far:
const today = new Date();
const day = today.getDate();
const month = today.getMonth() + 1;
const year = today.getFullYear();
const employees = [
["Frank", "Jagger", "6. 10.", "1984"],
["Ringo", "Lennon", "6. 10.", "1983"],
["John", "Star", "4. 10", "1962"],
["Mick", "Sinatra", "4. 10", "1961"]
];
let nameday;
let age;
let employeesName;
switch (dayMonth) {
case "6. 10.":
nameday = "Frank, Ringo, Steve";
break;
default:
nameday = '';
}
if (employees.includes(nameday)) {
document.write(`${employeesName} nameday today. Congratulations!`);
}
if (dayMonth === nameday) {
document.write(`John Star is ${age} today and Mick Sinatra is ${age} today. Congratulations!`);
}
I understand that the end of the code needs modification. How can I access and compare all the first names in the array correctly?
View the codepen here.