Just dipping my toes into the world of JavaScript and working on a fun little project - a binary clock (yes, I know, super geeky)
I've managed to write most of the code, but now I want to take it to the next level. Currently, the numbers are being displayed as strings of 0s and 1s, but I'd really like them to show as images instead: 0.png and 1.png, which are saved in the same directory...
Here's what I have so far. Ideally, I'd love for these changes to happen within the same function...
function binClock ()
{
var currentTime = new Date();
var currentYear = currentTime.getFullYear();
var currentMonth = currentTime.getMonth() + 1;
var currentDate = currentTime.getDate();
var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes();
var currentSeconds = currentTime.getSeconds();
currentYear = currentYear.toString(2);
currentMonth = currentMonth.toString(2);
currentDate = currentDate.toString(2);
currentHours = currentHours.toString(2);
currentMinutes = currentMinutes.toString(2);
currentSeconds = currentSeconds.toString(2);
document.getElementById("year").firstChild.nodeValue = currentYear;
document.getElementById("month").firstChild.nodeValue = currentMonth;
document.getElementById("date").firstChild.nodeValue = currentDate;
document.getElementById("hour").firstChild.nodeValue = currentHours;
document.getElementById("min").firstChild.nodeValue = currentMinutes;
document.getElementById("second").firstChild.nodeValue = currentSeconds;
}
To implement this on the webpage, I am calling the function on body load:
onload="binClock(); setInterval('binClock()', 1000)"