Added age.js to allow for automatic age update
This commit is contained in:
parent
189ca5034b
commit
87b2e808f7
@ -6,6 +6,8 @@
|
||||
<link rel="stylesheet" href="./style.css" />
|
||||
</head>
|
||||
|
||||
<script src="./js/flip.js"></script>
|
||||
<script src="./js/age.js"></script>
|
||||
|
||||
<div class="card" id="card" onclick="flipCard()">
|
||||
<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>{</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">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">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>
|
||||
@ -55,6 +57,4 @@
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="./js/flip.js"></script>
|
||||
</html>
|
10
js/age.js
Normal file
10
js/age.js
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user