-
Notifications
You must be signed in to change notification settings - Fork 1
/
ageGenerator.js
59 lines (47 loc) · 1.88 KB
/
ageGenerator.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
/* concept: we're going to tell the user how logn they've been on the planet in each of the following; days; weeks; months; seconds. we will ask for their dob in dd/mm/yyyy format and calculate the outputs based on this */
/* pseudo code */
//user is asked to enter their dob as a dd/mm/yyyy format
//once all three inputs are recieved, the submit button is highlighted
//user clicks submit
//calculation takes place
//outputs are presented to the screen
//clear button is highlighted
function calculate(){
var indate = document.getElementById('InDate').value;
var h2 = document.getElementsByTagName('h2')[0];
//how to convert DOB into dateformat?
//var datetest = Date.parse("December 8, 1988");
indate = Date.parse(indate);
//date.parse is super flexible and it can read in dates in many formats
//output of datetest will be in milliseconds: 1332288000000
var now = new Date();
//collects date now
var currentdate = Date.parse(now);
//parses it to milliseconds
console.log(indate);
console.log(currentdate);
var elapsed = currentdate - indate;
//calculates differnce between todays date and the input (ortest) date
//console.log(elapsed);
var millisPerDay = 1000*60*60*24;
//this equation provides amount of milliseconds per day
function millisToDays(inputMillis) {
var days = inputMillis / millisPerDay;
//divides the elapsed time (input as inputMillis) by the amount of milliseconds in days
return Math.floor(days);
//rounds the output down to lowest single number
}
var days = millisToDays(elapsed);
//calls the function millistoDays and passes the value of elapsed into it
//console.log("You've been alive for " + days + " days");
function display() {
h2.textContent = "You've been alive for " + days + " days";
}
display();
}
window.onload = function(){
var start = document.getElementById('startbutton');
start.onclick = function() {
calculate();
}
}