While learning JavaScript I thought it was a good idea to make a digital clock program. I followed a youtube tutorial (with some tweaks to my preference) and came up with my final code that I have. I came to CodeReview to get the script reviewed, and to ask is there anything wrong with the script and/or any way to improve it as a whole. Ways to make the script shorter (yet also high in performance) are also accepted. I am also curious on if I have any 'red flags' currently. I will be giving the best answers the green checkmark. Thanks!
function showTime() {
const date = new Date();
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds = date.getSeconds();
let session = (hours < 12) ? "AM" : "PM";
if (hours === 0) {
hours = 12;
} else if (hours > 12) {
hours -= 12;
}
hours = (hours < 10) ? '0' + hours : hours;
minutes = (minutes < 10) ? '0' + minutes : minutes;
seconds = (seconds < 10) ? '0' + seconds : seconds;
const time = `${hours} : ${minutes} : ${seconds} ${session}`;
document.querySelector('div').innerHTML = time;
setTimeout(showTime,1000)
}
showTime()
<!DOCTYPE html>
<html>
<head>
<title>Digital Clock</title>
</head>
<body>
<div></div>
<script src = "script.js"></script>
</body>
</html>
TL;DR: I am a JavaScript programmer, and CSS currently isn't my suite, therefore I know that the clock can use some styling. How can the JavaScript code be improved?