Skip to content

Instantly share code, notes, and snippets.

@jelinski
Created November 7, 2020 19:33
Show Gist options
  • Save jelinski/4ee27befb0df0a4f0011aead18477259 to your computer and use it in GitHub Desktop.
Save jelinski/4ee27befb0df0a4f0011aead18477259 to your computer and use it in GitHub Desktop.
Function that creates a rainbow clock on element given its ID
var createTimeUpdater = function (clockId){
var clockElement = document.getElementById(clockId);
var rainbowColors = [
"#FF0000",
"#FF7F00",
"#FFFF00",
"#00FF00",
"#0000FF",
"#2E2B5F",
"#8B00FF"
];
var index = 0;
return function(){
clockElement.innerText = (new Date()).toLocaleTimeString();
clockElement.style.color = rainbowColors[index];
index= (index + 1) % rainbowColors.length;
};
};
setInterval(createTimeUpdater("clock"), 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment