JavaScript/Vanilla JS

[๋ฐ”๋‹๋ผJS๋กœ ํฌ๋กฌ ์•ฑ ๋งŒ๋“ค๊ธฐ] Making a JS Clock part One

์ฝ”๋”ฉํ•˜๋Š” ๋ถ•์–ด 2021. 2. 26. 23:43
๋ฐ˜์‘ํ˜•

[์ถœ์ฒ˜-์œ ํŠœ๋ธŒ ๋…ธ๋งˆ๋“œ ์ฝ”๋” Nomad Coders]

https://youtu.be/f0nBj0YMBUI

-์ด๋ก  ๋. ์ด์ œ momentum์„ ๋งŒ๋“ค์ž

 

 

Google console ์ฐฝ์œผ๋กœ ๋ฏธ๋ฆฌ ์ถœ๋ ฅํ•ด๋ด„ 

 

 

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();

๋ฐ˜์‘ํ˜•