I was trying to create a clock following some tutorials on the internet but I'm having a problem. The clock should update itself every second and should show the current time. May I have your help please? This should be the result:https://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock . This is my code:
function startClock() {
var currentTime = new Date();
console.log(currentTime);
var currentHours = currentTime.getHours();
console.log(currentHours);
var currentMinutes = currentTime.getMinutes();
console.log(currentMinutes);
var currentSeconds = currentTime.getSeconds();
console.log(currentSeconds);
currentMinutes = checkTime(m);
currentSeconds = checkTime(s);
var time = currentHours + ":" + currentMinutes + ":" + currentSeconds;
document.getElementById("time").innerHTML = time;
var repeatTime = setTimeout(startClock, 1000);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
return i;
}
}