0
How does the code work?
function printTime(){ var d=new Date(); var hours=d.getHours(); var mins=d.getMinutes(); var secs=d.getSeconds(); document.body.innerHTML=hours+":"+mins+":"+secs; } setInterval(printTime,1000);
1 Answer
+ 3
The printTime function gets the current date and assigns it to variable d. Then gets the hours, minutes and seconds.
Then prints it in the document.
The setInterval calls the printTime function every 1000 milliseconds or 1 second.
Therefore, displaying a basic digital clock.