-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
52 lines (40 loc) · 1.79 KB
/
script.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
function calculateAge() {
var dayInput = document.getElementById('day');
var monthInput = document.getElementById('month');
var yearInput = document.getElementById('year');
var ageDays = document.getElementById('ageDays');
var ageMonths = document.getElementById('ageMonths');
var ageYears = document.getElementById('ageYears');
var birthDate = new Date(yearInput.value, monthInput.value - 1, dayInput.value);
var today = new Date();
var ageInMilliseconds = today - birthDate;
var ageInSeconds = Math.floor(ageInMilliseconds / 1000);
var ageInMinutes = Math.floor(ageInSeconds / 60);
var ageInHours = Math.floor(ageInMinutes / 60);
var ageInDays = Math.floor(ageInHours / 24);
var ageDate = new Date(ageInMilliseconds);
var ageYearsDiff = ageDate.getUTCFullYear() - 1970;
var ageMonthsDiff = ageDate.getUTCMonth();
var ageDaysDiff = ageDate.getUTCDate() - 1;
ageDays.textContent = ageDaysDiff;
ageMonths.textContent = ageMonthsDiff;
ageYears.textContent = ageYearsDiff;
liveMonths.textContent = liveMonthsDiff;
liveDays.textContent = liveDaysDiff;
}
function resetFields() {
var dayInput = document.getElementById('day');
var monthInput = document.getElementById('month');
var yearInput = document.getElementById('year');
var ageDays = document.getElementById('ageDays');
var ageMonths = document.getElementById('ageMonths');
var ageYears = document.getElementById('ageYears');
// Limpar os campos de entrada
dayInput.value = '';
monthInput.value = '';
yearInput.value = '';
// Limpar os resultados
ageDays.textContent = '';
ageMonths.textContent = '';
ageYears.textContent = '';
}