Skip to content

Commit 2d4c46b

Browse files
committed
Age calculator
1 parent 7fbabad commit 2d4c46b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

_includes/landing.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ <h3 class="font-weight-bold">Hi! Welcome to my website</h3>
5050
}
5151
</style>
5252

53+
<script src="{{ '/assets/js/age-calculator.js' | relative_url }}"></script>

assets/js/age-calculator.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function ageCalculator() {
2+
var today = new Date();
3+
var birthDate = new Date("2000-10-06"); // ISO-8601 format
4+
var age = today.getFullYear() - birthDate.getFullYear();
5+
var m = today.getMonth() - birthDate.getMonth();
6+
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
7+
age--;
8+
}
9+
10+
document.querySelector("#age").innerHTML = age;
11+
}
12+
13+
ageCalculator();

0 commit comments

Comments
 (0)