clock

mail@pastecode.io avatar
unknown
javascript
2 years ago
622 B
1
Indexable
Never
const convertToCorrectFormat = (number) => number < 10 ? `0${number}` : `${number}`;

const getTime = () => {
	const date = new Date();
    const hours = date.getHours();
    const minutes = date.getMinutes();
    const seconds = date.getSeconds();

    const time = `${hours}:${convertToCorrectFormat(minutes)}:${convertToCorrectFormat(seconds)}`;
    return time;
};


const render = () => {
	const element = document.getElementById("clock");
	
	const drawTime = () => {
		element.innerText = getTime();
		setTimeout(drawTime, 1000);
	};

	drawTime();
};

window.addEventListener("load", render);