프로그래밍/Javascript

#5 코드챌린지 크리스마스디데이

타코코딩 2023. 9. 14. 00:20
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <script type="module" src="./main.js"></script>
    <link
      rel="stylesheet"
      href="./style.css
    " />
    <title>Momentum</title>
  </head>
  <body>
    <h1>Time Until Christmas Eve</h1>
    <h2 class="js-clock"></h2>
  </body>
</html>
setInterval(() => {
  const now = new Date().getTime();
  const mas = new Date(`2023-12-25,00:00:00`).getTime();
  const leftTime = (mas - now) / 1000;
  const seconds = Math.floor(leftTime % 60);
  const minute = Math.floor(leftTime / 60) % 60;
  const hour = Math.floor(leftTime / (60 * 60)) % 24;
  const days = Math.floor(leftTime / (60 * 60 * 24));

  document.querySelector(
    "h2"
  ).innerHTML = `${days}day ${hour}hour ${minute}min ${seconds}sec`;
}, 1000);

https://nomadcoders.co/login

 

Log in – 노마드 코더 Nomad Coders

Log in to Nomad Coders

nomadcoders.co