JavaScript/Vanilla JS
[๋ฐ๋๋ผJS๋ก ํฌ๋กฌ ์ฑ ๋ง๋ค๊ธฐ] Making a JS Clock part One
์ฝ๋ฉํ๋ ๋ถ์ด
2021. 2. 26. 23:43
๋ฐ์ํ
[์ถ์ฒ-์ ํ๋ธ ๋ ธ๋ง๋ ์ฝ๋ Nomad Coders]
-์ด๋ก ๋. ์ด์ momentum์ ๋ง๋ค์
index.html
<!DOCTYPE html>
<html>
<head>
<title>Something</title>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div class="js-clock">
<h1>00:00</h1>
</div>
<script src="clock.js"></script>
</body>
</html>
clock.js
const clockContainer = document.querySelector(".js-clock"),
clockTitle = clockContainer.querySelector("h1");
function getTime(){
const date = new Date();
const minute = date.getMinutes();
const hours = date.getHours();
const seconds = date.getSeconds();
clockTitle.innerText = `${hours}:${minute}:${seconds}`;
}
function init(){
getTime();
}
init();
๋ฐ์ํ