Skip to content

Instantly share code, notes, and snippets.

@moitorrijos
Created May 26, 2013 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moitorrijos/5653713 to your computer and use it in GitHub Desktop.
Save moitorrijos/5653713 to your computer and use it in GitHub Desktop.
a javascript function to display a Greeting on a website depending on the hour of the day on the client's computer.
//getGreeting function
function getGreeting (hour) {
hour = hour || new Date().getHours();
if (typeof hour === "number"){
if (hour <= 12) {
return "Good Morning";
} else if (hour <= 17) {
return "Good Afternoon";
} else {
return "Good Evening";
}
} else {
alert("Hour has to be a number.");
}
}
getGreeting(12.5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment