Clock part One

์‹œ๊ณ„๋งŒ๋“ค๊ธฐ

const clockContainer = document.querySelector(".js_clock"),//js_clock ์„ ์„ ํƒ
      clockTitle =  clockContainer.querySelector("h1"); // js_clock์˜ h1


function getTime(){
  const date = new Date(); //Date์ƒ
  const minutes = date.getMinutes(); // Date getMinutes์„ minutes์— ์ €์žฅ 
  const hours = date.getHours();
  const seconds = date.getSeconds();
  clockTitle.innerText=`${hours}:${minutes}:${seconds}`; 
};

 getTime(); // ํ˜„์ œ ์‹œ๊ฐ„,๋ถ„,์ดˆ ๋กœ h1์— ์ถœ๋ ฅ์ด๋จ

setInterval(ํ•จ์ˆ˜๋ช…,์‹คํ–‰ํ•  ์‹œ๊ฐ„)

setInterval(fn,10000);  // ๊ธฐ๋ณธํ˜•

function sayHi(){
  console.log("sayHi");
};

setInterval(sayHi, 3000); // 3์ดˆ๋งˆ๋‹ค sayHi๋ฅผ ์ถœ๋ ฅํ•จ

์‹œ,๋ถ„,์ดˆ๊ฐ€ 10๋ณด๋‹ค ์ž‘์„๋•Œ ์•ž์— 0์ด๋ผ๋Š” ์ˆซ์ž ๋ถ™์—ฌ์ฃผ๊ธฐ

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 }`;
//๋งŒ์•ฝ์— hours , minutes , seconds๊ฐ€ 10๋ณด๋‹ค ์ž‘๋‹ค๋ฉด  ์•ž์— 0 ์„ ๋ถ™์—ฌ์ค˜
//? -> ์ฐธ์ธ์ง€ ๊ฑฐ์ง“์ธ์ง€ 
//ํ™•์ธํ•œํ›„ : -> ์ฐธ์ผ๋•Œ๋Š” : ์ „๊ฐ’์„ ๋ฆฌํ„ด ๊ฑฐ์ง“์ผ๋•Œ๋Š” : ์ดํ›„์˜ ๊ฐ’์„ ๋ฆฌ์ปจ (์ž‘์€ if๋ฌธ ๊ฐ™์€ ์—ญํ™œ)
  
};

 getTime();

function init(){

  getTime();
  setInterval(getTime, 1000); // ํ˜„์žฌ์‹œ๊ฐ„์ด ์ถœ๋ ฅ๋จ
};

init();

localStorage

๋‚˜์˜ ๋ธŒ๋ผ์šฐ์ €์— ์ €์žฅ๋œ ์ •๋ณด๋“ค์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

Last updated