-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
75 lines (62 loc) · 2.27 KB
/
index.html
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
70
71
72
73
74
75
<!doctype html>
<html>
<body>
<h1>Ramanujan!</h1>
<input id="bday" type="date">
<div> <span id="seconds"></span> seconds</div>
<div> <span id="minutes"></span> minutes</div>
<div> <span id="hours"></span> hours</div>
<div> <span id="days"></span> days</div>
<div> <span id="weeks"></span> weeks</div>
<div> <span id="months"></span> months</div>
<div> <span id="years"></span> years</div>
<div> <span id="foo"></span> next second power of ten</div>
<script>
const el = document.getElementById.bind(document);
function update() {
const bday = el("bday");
const bdayMillis = new Date(bday.value).getTime();
const nowMillis = new Date().getTime();
const ageMillis = (nowMillis - bdayMillis);
const seconds = Math.floor(ageMillis / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const weeks = Math.floor(days / 7);
const years = Math.floor(days / 365.24);
const months = Math.floor(12 * days / 365.24);
el("seconds").innerHTML = seconds.toLocaleString();
el("minutes").innerHTML = minutes.toLocaleString();
el("hours").innerHTML = hours.toLocaleString();
el("days").innerHTML = days.toLocaleString();
el("weeks").innerHTML = weeks.toLocaleString();
el("months").innerHTML = months.toLocaleString();
el("years").innerHTML = years.toLocaleString();
let nextSecondsPowerOfTen = nextPowerOfTen(seconds);
let delta = nextSecondsPowerOfTen - seconds;
let date = new Date(nowMillis + 1000 * delta);
el("foo").innerHTML = date.toLocaleDateString();
}
el("bday").addEventListener("change", update);
go();
function go() {
update();
window.requestAnimationFrame(go);
}
function isPrime(n) {
const limit = Math.ceil(Math.sqrt(n));
for (let i = 2; i <= limit; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
function nextPowerOfTen(n) {
return 10 ** Math.ceil(Math.log10(n));
}
//this is Ivan...
console.log("kilroy wuz here");
</script>
</body>
</html>