-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (55 loc) · 1.35 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$(document).ready(function(){
$("#submit").click(function(e){
e.preventDefault();
var input = $("#dob-input").val();
var dob = new Date(input);
save(dob);
renderAgeLoop();
});
function save(dob)
{
localStorage.dob = dob.getTime();
};
function load()
{
var dob;
if (dob = localStorage.getItem("dob"))
{
return new Date(parseInt(dob));
}
return -1;
};
function renderAgeLoop()
{
var dob = load();
$("#choose").css("display", "none");
$("#timer").css("display", "block");
setInterval(function(){
var age = getAge(dob);
$("#age").html(age.year + "<sup>." + age.ms + "</sup>");
}, 100);
};
function renderChoose()
{
$("#choose").css("display", "block");
};
function getAge(dob){
var now = new Date;
var duration = now - dob;
var years = duration / 31556900000;
var majorMinor = years.toFixed(9).toString().split('.');
return {
"year": majorMinor[0],
"ms": majorMinor[1]
};
};
function main() {
if (load() != -1)
{
renderAgeLoop();
} else {
renderChoose();
}
};
main();
});