Skip to content

Instantly share code, notes, and snippets.

@yakirh
Created October 13, 2013 14:40
Show Gist options
  • Select an option

  • Save yakirh/6963068 to your computer and use it in GitHub Desktop.

Select an option

Save yakirh/6963068 to your computer and use it in GitHub Desktop.
Time range exercise
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1 id="message"></h1>
<script type="text/javascript">
var now = new Date,
hours_float = now.getHours()+(now.getMinutes()/60),
time_ranges = [
// [ Start, End, Label ]
[ 6.5, 12, 'Morning' ],
[ 12, 17, 'Afternoon' ],
[ 17, 22, 'Evening' ],
[ 22, 6, 'Night' ]
],
i;
for (i = 0; i < time_ranges.length; i++) {
if (hours_float >= time_ranges[i][0] && hours_float <= time_ranges[i][1]) {
document.getElementById('message').innerHTML = 'Good '+time_ranges[i][2];
break;
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment