-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyAge.html
More file actions
101 lines (89 loc) · 2.67 KB
/
Copy pathmyAge.html
File metadata and controls
101 lines (89 loc) · 2.67 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Age</title>
<style>
:root{
--main-color: #138f13;
--second-color: #58dbb4;
}
#age{
margin: auto;
width: 50%;
height: max-content;
border: var(--main-color) 2px solid;
border-radius: 10px;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
margin-top: 20%;
background-image: linear-gradient(45deg, #58dbb4 10%, #138f13 100%);
}
form{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 20px;
margin-bottom: 20px;
}
input{
margin: 10px;
padding: 5px;
border-radius: 5px;
border: var(--second-color) 2px solid;
text-align: center;
width: 200px;
height: 30px;
font-size: 1rem;
background-color: rgb(158, 238, 151);
color: black;
}
button{
padding: 5px 10px;
margin: auto;
border-radius: 5px;
border: solid 2px white;
background-color: #28a745;
color: white;
cursor: pointer;
width: 120px;
height: 45px;
font-size: 1rem;
}
#result{
margin-bottom: 20px;
display: none;
}
</style>
</head>
<body>
<div id="age">
<h1>Welcome to Age Calculator</h1>
<p>Please enter your year of birth:</p>
<form id="ageForm">
<label for="yearOfBirth">Year of Birth:</label>
<input type="number" id="yearOfBirth" min="1980" max="2025" required>
<button id="btn" type="submit">Calculate</button>
</form>
<div id="result">
<h2>Your Age is: <span id="ageDisplay"></span></h2>
</div>
</div>
<script>
const btn = document.getElementById("btn");
const form = document.getElementById("ageForm");
form.addEventListener("submit", function(event) {
event.preventDefault();
const yearOfBirth= document.getElementById("yearOfBirth").value;
const currentYear= new Date().getFullYear();
const age= currentYear - yearOfBirth;
document.getElementById("result").style.display = "block";
document.getElementById("ageDisplay").textContent = `${age} years old`;
});
</script>
</body>