2020-06-07 09:18:09 +02:00
|
|
|
const greeterMessage = document.getElementById("greeterMessage");
|
|
|
|
const dateMessage = document.getElementById("dateMessage");
|
2020-06-04 04:45:26 +02:00
|
|
|
|
2020-06-07 09:18:09 +02:00
|
|
|
const date = new Date();
|
|
|
|
const hour = date.getHours();
|
|
|
|
let greeterSuffix;
|
2020-06-04 04:45:26 +02:00
|
|
|
|
|
|
|
const monthsArr = [
|
|
|
|
"January",
|
|
|
|
"February",
|
|
|
|
"March",
|
|
|
|
"April",
|
|
|
|
"May",
|
|
|
|
"June",
|
|
|
|
"July",
|
|
|
|
"August",
|
|
|
|
"September",
|
|
|
|
"October",
|
|
|
|
"November",
|
|
|
|
"December"
|
|
|
|
];
|
|
|
|
|
|
|
|
const daysArr = [
|
|
|
|
"Sunday",
|
|
|
|
"Monday",
|
|
|
|
"Tuesday",
|
|
|
|
"Wednesday",
|
|
|
|
"Thursday",
|
|
|
|
"Friday",
|
|
|
|
"Saturday"
|
|
|
|
]
|
|
|
|
|
2020-06-04 04:47:58 +02:00
|
|
|
const getDayOrdinal = (day) => {
|
|
|
|
return day + (day > 0 ? ['th', 'st', 'nd', 'rd'][(day > 3 && day < 21) ||
|
|
|
|
day % 10 > 3 ? 0 : day % 10] : '');
|
|
|
|
}
|
|
|
|
|
|
|
|
const updateGreeterDateMessage = () => {
|
|
|
|
if (hour >= 6 && hour < 12) {
|
|
|
|
greeterSuffix = "Morning";
|
|
|
|
} else if (hour >= 12 && hour < 18) {
|
|
|
|
greeterSuffix = "Afternoon";
|
|
|
|
} else {
|
|
|
|
greeterSuffix = "Evening";
|
|
|
|
}
|
|
|
|
|
|
|
|
greeterMessage.innerHTML = "Good" + "<br>" + greeterSuffix + "!";
|
|
|
|
|
|
|
|
dateMessage.innerHTML = "Today is the " + getDayOrdinal(date.getDate()) +
|
|
|
|
" of " + monthsArr[date.getMonth()] + ", and it's " + daysArr[date.getDay()] + ".";
|
2020-06-04 04:45:26 +02:00
|
|
|
}
|
|
|
|
|
2020-06-04 04:47:58 +02:00
|
|
|
window.onload = updateGreeterDateMessage();
|