mercredi 20 mars 2019

Why can't I print the current time alongside the if/else statement that uses the current time also?

I'm not sure why I can't print the message alongside the current time. The current time only prints when I comment out the if/else/else logic statement. I'm not sure why this is happening

let currentdate = new Date();
let tod = currentdate.getHours();
let dateTime =
  currentdate.getDate() +
  "/" +
  (currentdate.getMonth() + 1) +
  "       " +
  currentdate.getHours() +
  ":" +
  currentdate.getMinutes();

window.onload = function() {
  document.getElementById("time").innerHTML = dateTime;
};

if (tod < 11) {
  message = "Good Morning.";
} else if (tod < 16) {
  message = "Good Afternoon.";
} else {
  message = "Good Evening.";
}
window.onload = function() {
  document.getElementById("tod").innerHTML = message;
};

Aucun commentaire:

Enregistrer un commentaire