Added age.js to allow for automatic age update

This commit is contained in:
Luke Else 2022-04-28 18:18:49 +01:00
parent 189ca5034b
commit 87b2e808f7
2 changed files with 18 additions and 8 deletions

View File

@ -6,6 +6,8 @@
<link rel="stylesheet" href="./style.css" /> <link rel="stylesheet" href="./style.css" />
</head> </head>
<script src="./js/flip.js"></script>
<script src="./js/age.js"></script>
<div class="card" id="card" onclick="flipCard()"> <div class="card" id="card" onclick="flipCard()">
<div class="card-back" id="card-back"> <div class="card-back" id="card-back">
@ -24,7 +26,7 @@
<span class="method">Person </span><span class="function">me </span><span class="operator">= </span><span class="variable">new </span><span class="method">Person</span> <br /> <span class="method">Person </span><span class="function">me </span><span class="operator">= </span><span class="variable">new </span><span class="method">Person</span> <br />
<span>{</span> <span>{</span>
<div class="indent"> <span class="property">Name </span><span>= </span><span class="string">"Luke Else"</span><span>,</span></div> <div class="indent"> <span class="property">Name </span><span>= </span><span class="string">"Luke Else"</span><span>,</span></div>
<div class="indent"> <span class="property">Age </span><span>= </span><span class="int age">18</span><span>,</span></div> <div class="indent"> <span class="property">Age </span><span>= </span><span class="int"><script>document.write(getAge(new Date("2004-01-12")))</script></span><span>,</span></div>
<div class="indent"> <span class="property">Title </span><span>= </span><span class="string">"Software Engineer / Student"</span><span>,</span></div> <div class="indent"> <span class="property">Title </span><span>= </span><span class="string">"Software Engineer / Student"</span><span>,</span></div>
<div class="indent"> <span class="property">EMail </span><span>= </span><a href="mailto:contact@luke-else.co.uk"><span class="string">"contact@luke-else.co.uk"</span></a><span>,</span></div> <div class="indent"> <span class="property">EMail </span><span>= </span><a href="mailto:contact@luke-else.co.uk"><span class="string">"contact@luke-else.co.uk"</span></a><span>,</span></div>
<div class="indent"> <span class="property">Website </span><span>= </span><a href="https://git.luke-else.co.uk/luke-else"><span class="string">"git.luke-else.co.uk"</span></a></div> <div class="indent"> <span class="property">Website </span><span>= </span><a href="https://git.luke-else.co.uk/luke-else"><span class="string">"git.luke-else.co.uk"</span></a></div>
@ -55,6 +57,4 @@
</code> </code>
</div> </div>
</div> </div>
<script src="./js/flip.js"></script>
</html> </html>

10
js/age.js Normal file
View File

@ -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;
}