Skip to content

Commit d0438d0

Browse files
committed
Precise Age Calculator
1 parent c588849 commit d0438d0

5 files changed

Lines changed: 45 additions & 2 deletions

File tree

index.css

Whitespace-only changes.

index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Agent's Site</title>
88
<script src="index.js"></script>
9-
<link rel="stylesheet" href="index.css">
109
</head>
1110
<body>
12-
<h1>come back later when theres something interesting here</h1>
11+
<a href="./precise-age/index.html">Precise Age Calculator</a>
1312
</body>
1413
</html>

precise-age/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Precise Age Calculator</title>
8+
<link rel="stylesheet" href="./stylesheet.css">
9+
</head>
10+
<body>
11+
<h1>Precise Age Calculator</h1>
12+
<p>Birth Date</p>
13+
<input type="datetime-local" id="date">
14+
<br>
15+
<br>
16+
<br>
17+
<button onclick="window.calculate()">Calculate</button>
18+
<br>
19+
<br>
20+
<br>
21+
<h2 id="age">Age: ??</h2>
22+
</body>
23+
<script src="index.js"></script>
24+
</html>

precise-age/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const secondsInYear = 31536000
2+
const millisecondsToSeconds = 0.001
3+
4+
const dateInput = document.getElementById("date")
5+
const age = document.getElementById("age")
6+
7+
let interval = false
8+
9+
window.calculate = () => {
10+
const date = new Date(dateInput.value)
11+
age.innerHTML = "Age: " + ((Date.now() * millisecondsToSeconds) - (date.getTime() * millisecondsToSeconds)) / secondsInYear
12+
13+
if (!interval) {
14+
interval = true
15+
setInterval(window.calculate, 100)
16+
}
17+
}

precise-age/stylesheet.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
text-align: center;
3+
}

0 commit comments

Comments
 (0)