Depending on the time of the day. I am trying to display Morning, Afternoon or Evening to the user using the JavaScript ( new Date() ) method. But what I am receiving in response is just the (else) statement. Can I get advice as to what I am doing incorrectly?
const mainHeader = document.getElementById("header");
var greetings = () => {
var today = new Date();
}
window.onload= (e) => {
greetings;
if(today >= 1 && today < 12) {
mainHeader.innerHTML = "<h3>Good Morning! And Welcome To Guess The Number</h3>"
console.log("Morning: between 1 and 12");
} else if(today >= 12 && today < 17) {
mainHeader.innerHTML = "<h3>Good Afternoon! And Welcome To Guess The Number</h3>"
console.log("Afternoon: between 12 and 17");
} else if(today >= 17 && today <= 24) {
mainHeader.innerHTML = "<h3>Good Evening! And Welcome To Guess The Number</h3>"
console.log("Evening: between 17 and 24");
} else {
mainHeader.innerHTML = "<h3>Welcome to Guess The Number</h3>"
console.log("No time zone");
}
}
Aucun commentaire:
Enregistrer un commentaire