Last active
December 10, 2020 11:49
-
-
Save jdgo-mars/2a2515034b29545abba769561eef9e11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const weekday = { | |
0: "Sunday", | |
1: "Monday", | |
2: "Tuesday", | |
3: "Wednesday", | |
4: "Thursday", | |
5: "Friday", | |
6: "Saturday", | |
} | |
function getToday() { | |
const today = new Date(); | |
const todayString = `It's ${weekday[today.getDay()]}! It's ${today.getHours()}:${today.getMinutes()}:${today.getSeconds()}`; | |
$('#currentTimeParagraph').text(todayString); | |
} | |
function daysLeft() { | |
const today = new Date(); | |
const urlParams = new URLSearchParams(window.location.search); | |
const targetYear = urlParams.get('targetYear') | today.getFullYear(); | |
const christmas = new Date(); | |
christmas.setDate(24); | |
christmas.setMonth(11); | |
const diff = christmas.getTime() - today.getTime(); | |
const yearDiff = targetYear - today.getFullYear() | |
$('#christmasTime').text(`Days until Christmas: ${diff / (1000 * 60 * 60 * 24) + (365 * yearDiff)} days`); | |
} | |
$(document).ready(() => { | |
daysLeft(); | |
getToday(); | |
setInterval(getToday, 1000); | |
}); | |
// run `npx http-server` on your project folder | |
// open `localhost:8080` on browser | |
// try using a targetYear | |
// using url `localhost:8080?targetYear=2021` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment