I'm trying to display the time on a clock that I created on my website, so I used the setInterval to display the time every seconds. But it only runs once and I don't know what to do. However, Firefox doesn't notice any error in my code.
var date = new Date(); //Time of the clock in-game
var hours;
var minutes;
var seconds;
var display_hours; // Displayers for the time
var display_minutes;
var display_seconds;
window.onload = function() {
display_hours = document.getElementById("hour");
display_minutes = document.getElementById("minute");
display_seconds = document.getElementById("second");
};
function time_on() {
hours = date.getHours();
if (hours < 10) {
hours = "0" + hours;
};
minutes = date.getMinutes();
if (minutes < 10) {
minutes = "0" + minutes;
};
seconds = date.getSeconds();
if (seconds < 10) {
seconds = "0" + seconds;
};
display_hours.textContent = hours;
display_minutes.textContent = minutes;
display_seconds.textContent = seconds;
};
var go_time = setInterval(time_on, 1000); // Display time on the clock every seconds
I want to be able to clear this interval later in the code.