I attempted to create a clock by following various online tutorials, but I'm encountering an issue. The goal is to have the clock update itself every second and display the current time. Could you please assist me with this? Here is what I would like to achieve: https://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock. Below is the code snippet that I have been working on:
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;
}
}