-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathageCalculator.html
More file actions
73 lines (60 loc) · 1.78 KB
/
Copy pathageCalculator.html
File metadata and controls
73 lines (60 loc) · 1.78 KB
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
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<title>Age Calculator</title>
<style>
body{
font-family: Arial;
background-color: #ccc;
}
.container{
background-color:white;
display:flex;
flex-direction:column;
margin:100px auto;
padding:20px;
box-shadow: 0px 0px 10px 0px grey;
border-radius: 10px;
}
h1{
text-align: center;
}
input{
padding: 10px;
margin-bottom: 10px;
}
button{
background-color: blue;
color:white;
font-size:18px;
border:none;
padding:10px;
cursor:pointer;
}
.js-res{
text-align:center;
font-size:18px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>Age Calculator</h1>
<p>Enter your birth date:</p>
<input type="date" class="birthDate">
<button onclick="calculateAge();">Calculate</button>
<p class="js-res"></p>
</div>
<script>
function calculateAge(){
let birthDate = document.querySelector('.birthDate');
let result = document.querySelector('.js-res');
let birth = new Date(birthDate.value);
let today = new Date();
let age = today.getFullYear() - birth.getFullYear();
result.innerHTML = `You are ${age} years old`;
}
</script>
</body>
</html>