diff --git a/projects/countdown-timer/app.js b/projects/countdown-timer/app.js new file mode 100644 index 0000000..73be0bf --- /dev/null +++ b/projects/countdown-timer/app.js @@ -0,0 +1,61 @@ +var button = document.getElementById("button"); +const input = document.querySelectorAll(".select"); + +button.addEventListener('click', ()=> { + var enterDate = document.getElementById("enterDate").value; + var enterTime = document.getElementById("enterTime").value; + + const last = enterDate + " " + enterTime; + const end = new Date(last); + + calculate(end); + + const myInterval = setInterval( + () => { + calculate(end); + }, + 1000 + ) + + var stop = document.getElementById("stop"); + stop.addEventListener('click', () => { + clearInterval(myInterval); + }) +}) + +const calculate = (end) => { + const now = new Date(); + + if(end > now) + { + const diff = (end - now)/1000; + + // convert into day + var day = Math.floor(diff / (3600 * 24)); + input[0].value = day; + + // convert into hour + var hour = Math.floor((diff / 3600) % 24); + input[1].value = hour; + + // convert into min + var min = Math.floor((diff / 60) % 60); + input[2].value = min; + + //convert into sec + var sec = Math.floor(diff % 60); + input[3].value = sec; + } + else + { + input[0].value = 0; + input[1].value = 0; + input[2].value = 0; + input[3].value = 0; + } +} + +var reset = document.getElementById("reset"); +reset.addEventListener('click', () => { + window.location.reload(); +}) \ No newline at end of file diff --git a/projects/countdown-timer/index.html b/projects/countdown-timer/index.html new file mode 100644 index 0000000..d0a7c1f --- /dev/null +++ b/projects/countdown-timer/index.html @@ -0,0 +1,58 @@ + + + + + + + + Countdown Timer + + + + +

Countdown Timer

+
+ + + + + +
+ + + + +
+ +
+ + + + + +
+
+ +
+

Day

+
+
+ +
+

Hour

+
+
+ +
+

Minutes

+
+
+ +
+

Seconds

+
+
+ + + + \ No newline at end of file diff --git a/projects/countdown-timer/style.css b/projects/countdown-timer/style.css new file mode 100644 index 0000000..a952887 --- /dev/null +++ b/projects/countdown-timer/style.css @@ -0,0 +1,79 @@ +html +{ + height: 100%; + font-weight: bolder; +} + +body +{ + text-align: center; + background-image: url("https://img.freepik.com/free-photo/neutral-tone-abstract-invitation-card_53876-97500.jpg?w=360&t=st=1678787861~exp=1678788461~hmac=ddf4b178837a6bad7c846053fe79fdfbc1e65bb4e3ee5c298f828b653335b6ed"); + background-position: center; + background-repeat: no-repeat; + background-size: 100%; + color:black; +} +table{ + margin: auto; +} +tr, td{ + text-align: left; +} + +.title +{ + font-size: 40px; + padding:1rem ; + border: 1px solid #ffdfdd; +} + +.dateTime label +{ + font-size: 20px; + margin: 10px; +} + +.dateTime input +{ + font-size: 20px; + margin: 10px; + padding: 5px 10px; + border: 2px solid #ffdfdd ; + background-color: #ffdfdd; + border-radius: 10px; + box-shadow: 3px 3px 3px #307d7e; +} + +button +{ + margin: 20px 5px; + padding: 5px 10px; + font-size: 20px; + background-color: #ffdfdd; + border: 1px solid #ffdfdd; + box-shadow: 3px 3px 3px #307d7e; + border-radius: 5px; +} + +.container +{ + display: flex; + justify-content: center; +} + +.innerContainer +{ + margin: 5px; +} + +.innerContainer input +{ + height: 8vw; + width: 8vw; + border-radius: 200px; + color: black; + background-color: #ffdfdd; + /* background: transparent; */ + text-align: center; + font-size: 5vw; +} \ No newline at end of file