노마드 코더님의 자바스크립트 강의를 보고 정리한 글입니다.
<!DOCTYPE html>
<html>
<head>
<title>Something</title>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div class="js-clock">
<h1></h1>
</div>
<script src="clock.js"></script>
</body>
</html>
const clockContainer = document.querySelector(".js-clock"),
clockTitle = clockContainer.querySelector("h1");
function getTime(){
const date = new Date();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
clockTitle.innerText = `${hours}:${minutes}:${seconds}`;
}
function init(){
getTime();
setInterval(getTime, 1000);
}
init();
condition ? block(true) : block(false)
clockTitle.innerText = `${hour < 10 ? `0${hours}` : hours}:${minutes < 10 ? `0${minutes}` : minutes}:${seconds < 10 ? `0${seconds}` : seconds}`;