-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
69 lines (55 loc) · 1.84 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* --------------------------
Sets Clock with callback functions
-------------------------- */
const clock = document.getElementById('time');
function pad(num) {
if ( num < 10 ) {
return `0${num}`;
}
return num;
}
const setTime = function() {
const timeNow = "";
const time = new Date();
let hh = pad(time.getHours());
const mm = pad(time.getMinutes());
const ss = pad(time.getSeconds());
if (hh > 12) {
hh = hh - 12;
clock.textContent = `The Current Time is: ${hh}:${mm}:${ss}PM`;
} else if (hh == 0) {
hh = 12;
clock.textContent = `The Current Time is: ${hh}:${mm}:${ss}AM`;
} else {
clock.textContent = `The Current Time is: ${hh}:${mm}:${ss}AM`;
}
}
setTime();
setInterval( setTime, 1000);
/* --------------------------
Sets Age
-------------------------- */
const myAge = document.getElementById('age');
const birthday = new Date(1987, 12, 3);
let today = new Date();
let age = ( today - birthday ) / 1000 / 60 / 60 / 24 / 365.25;
age = Math.floor(age);
myAge.textContent = `Age: ${age}`;
/* --------------------------
Sets Countdown to My Birthday!
-------------------------- */
const countdownText = document.getElementById('countdown');
const birthdayCountdown = function () {
let nextBirthday = new Date("Dec 3, 2020 00:00:00 CST-1200");
Date.parse(nextBirthday);
const today = new Date();
let countdown = nextBirthday - today;
countdown = new Date(countdown);
let days = Math.floor(countdown / 1000 / 60 / 60 /24);
let hours = countdown.getHours();
let minutes = countdown.getMinutes();
let seconds = countdown.getSeconds();
const message = `${days} days, ${hours} hours, ${minutes} minutes, ${seconds} seconds til my birthday!!`;
countdownText.textContent = `${message}`;
};
setInterval(birthdayCountdown, 1000);