๋ฐ์ํ
[์ถ์ฒ-์ ํ๋ธ ๋ ธ๋ง๋ ์ฝ๋ Nomad Coders]
setInterval(fn, 1000)
์ฒซ ๋ฒ์งธ ์ธ์๋ ํจ์, ๋ ๋ฒ์งธ ์ธ์๋ ์คํํ ์๊ฐ ๊ฐ๊ฒฉ(millisecond)์ด๋ค
const clockContainer = document.querySelector(".js-clock"),
clockTitle = clockContainer.querySelector("h1");
function getTime(){
const date = new Date();
const minutes = date.getMinutes();
const hours = date.getHours();
const seconds = date.getSeconds();
clockTitle.innerText = `${hours}:${minutes}:${seconds}`;
}
function init(){
getTime();
setInterval(getTime, 1000);
}
init();
-์ผํญ์ฐ์ฐ์ ์ฌ์ฉํ๊ธฐ
${seconds < 10 ? `0${seconds}` : seconds}`
const clockContainer = document.querySelector(".js-clock"),
clockTitle = clockContainer.querySelector("h1");
function getTime(){
const date = new Date();
const minutes = date.getMinutes();
const hours = date.getHours();
const seconds = date.getSeconds();
clockTitle.innerText = `${hours}:${minutes}:${seconds < 10 ? `0${seconds}` : seconds}`;
}
function init(){
getTime();
setInterval(getTime, 1000);
}
init();
const clockContainer = document.querySelector(".js-clock"),
clockTitle = clockContainer.querySelector("h1");
function getTime(){
const date = new Date();
const minutes = date.getMinutes();
const hours = date.getHours();
const seconds = date.getSeconds();
clockTitle.innerText = `${hours < 10 ? `0${hours}` : hours}:${
minutes < 10 ? `0${minutes}` : minutes
}:${seconds < 10 ? `0${seconds}` : seconds}`;
}
function init(){
getTime();
setInterval(getTime, 1000);
}
init();
๋ฐ์ํ
๋๊ธ