From 87b2e808f726bb18152b3cef2f3a5db109c93a52 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Thu, 28 Apr 2022 18:18:49 +0100 Subject: [PATCH] Added age.js to allow for automatic age update --- index.html | 16 ++++++++-------- js/age.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 js/age.js diff --git a/index.html b/index.html index 726a705..0032461 100644 --- a/index.html +++ b/index.html @@ -1,11 +1,13 @@ - - - Luke Else - - + + + Luke Else + + + +
@@ -24,7 +26,7 @@ Person me = new Person
{
Name = "Luke Else",
-
Age = 18,
+
Age = ,
Title = "Software Engineer / Student",
@@ -55,6 +57,4 @@
- - \ No newline at end of file diff --git a/js/age.js b/js/age.js new file mode 100644 index 0000000..0c31204 --- /dev/null +++ b/js/age.js @@ -0,0 +1,10 @@ +function getAge(dateString) { + var today = new Date(); + var birthDate = dateString; + var age = today.getFullYear() - birthDate.getFullYear(); + var m = today.getMonth() - birthDate.getMonth(); + if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { + age--; + } + return age; +} \ No newline at end of file