Skip to content

Instantly share code, notes, and snippets.

@victoriadrake
Created May 19, 2017 14:08
Show Gist options
  • Save victoriadrake/79247ed3c9b3a4e03a3190097b4d2b39 to your computer and use it in GitHub Desktop.
Save victoriadrake/79247ed3c9b3a4e03a3190097b4d2b39 to your computer and use it in GitHub Desktop.
Bit of jQuery that changes a message when the page loads, dpending on the current hour.
// changes based on current time
var time = new Date().getMinutes();
// sets the time to every ten minutes
var index = Math.floor(time/10);
var json = {
0:"Clever message zero.",
1:"Clever message one.",
2:"Clever message two.",
3:"Clever message three.",
4:"Clever message four.",
5:"Clever message five."
};
function getTagline(json, index) {
//gets message that corresponds to time index
$('#tagline').html(json[index]);
}
$(document).ready(function() {
getTagline(json, index);
//you can click on the field to advance and loop through messages
$('#tagline').on('click', function(){
if (index == 5) {index = -1;}
getTagline(json, index+=1);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment