For some reason, the timeout doesn't work, and the clock numbers stay the same as they started initially. I tried setInterval() but it didn't work either.
Code below, or see it here: codepen
// Variables
var hourN = document.getElementById("hoursD");
var minuteN = document.getElementById("minutesD");
var secondN = document.getElementById("secondsD");
var hour, minute, second = 0;
var date = new Date();
// Functions
function refresh() {
hour = date.getHours();
minute = date.getMinutes();
second = date.getSeconds();
hour > 12 ? hour = hour - 12 : hour;
hourN.innerText = hour;
minuteN.innerText = minute;
secondN.innerText = second;
var t = setTimeout(function(){ refresh(); }, 1000);
}
refresh();
<h1 align="center">
<span id="hoursD"></span> : <span id="minutesD"></span> : <span id="secondsD"></span>
</h1>