import '../styles/counter.css' import { Countdown } from './counter.js' const buttonInit = document.querySelector('#init'); const buttonStart = document.querySelector('#start'); // Get the new year const getNewYear = () => { const currentYear = new Date().getFullYear(); return new Date(`January 01 ${currentYear + 1} 00:00:00`); }; // select elements const app = document.querySelector('.countdown-timer'); const message = document.querySelector('.message'); const heading = document.querySelector('h1'); const format = (t) => { return t < 10 ? '0' + t : t; }; const render = (time) => { app.innerHTML = `

${format(time.days)}

Days

${format(time.hours)}

Hours

${format(time.minutes)}

Minutes

${format(time.seconds)}

Seconds
`; }; const showMessage = () => { message.innerHTML = `Terminé !`; app.innerHTML = ''; heading.style.display = 'none'; }; const hideMessage = () => { message.innerHTML = ''; heading.style.display = 'block'; }; const complete = () => { showMessage(); // restart the countdown after showing the // greeting message for a day () setTimeout(() => { hideMessage(); countdownTimer.setExpiredDate(getNewYear()); }, 1000 * 60 * 60 * 24); }; const countdownTimer = new Countdown( getNewYear(), render, complete );