Created
May 26, 2013 19:09
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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