File tree Expand file tree Collapse file tree 2 files changed +84
-0
lines changed
Expand file tree Collapse file tree 2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+
4+ < head >
5+ < meta charset ="UTF-8 ">
6+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8+ < title > My Age</ title >
9+ < style >
10+ : root {
11+ --main-color : # 138f13 ;
12+ --second-color : # 58dbb4 ;
13+ }
14+ # age {
15+ margin : auto;
16+ width : 50% ;
17+ height : 300px ;
18+ border : var (--main-color ) 2px solid;
19+ border-radius : 10px ;
20+ display : flex;
21+ flex-direction : column;
22+ align-items : center;
23+ text-align : center;
24+ margin-top : 20% ;
25+ background-image : linear-gradient (45deg , # 58dbb4 10% , # 138f13 100% );
26+
27+ }
28+ input {
29+ margin : 10px ;
30+ padding : 5px ;
31+ border-radius : 5px ;
32+ border : var (--second-color ) 2px solid;
33+ text-align : center;
34+ width : 200px ;
35+ height : 30px ;
36+ font-size : 1rem ;
37+ background-color : rgb (158 , 238 , 151 );
38+ color : black;
39+
40+ }
41+ button {
42+ padding : 5px 10px ;
43+ margin : auto;
44+ border-radius : 5px ;
45+ border : solid 2px white;
46+ background-color : # 28a745 ;
47+ color : white;
48+ cursor : pointer;
49+ width : 120px ;
50+ height : 45px ;
51+ font-size : 1rem ;
52+ }
53+ </ style >
54+ </ head >
55+ < body >
56+ < div id ="age ">
57+
58+ < h1 > Welcome to Age calculator </ h1 >
59+ < p > please Enter your year of birth:</ p >
60+ < input type ="number " id ="yeateOfBirth " min ="1980 " max ="2025 " >
61+ < button id ="btn "> calculate</ button >
62+ </ div >
63+ </ body >
Original file line number Diff line number Diff line change 1+ // Your birthdate
2+ const birthYear = 1992 ;
3+ const birthMonth = 3 ; // March (1 = January, 2 = February, 3 = March, etc.)
4+ const birthDay = 21 ; // replace with your actual day of birth
5+
6+ // Current date
7+ const today = new Date ( ) ;
8+ const currentYear = today . getFullYear ( ) ;
9+ const currentMonth = today . getMonth ( ) + 1 ; // getMonth() is 0-based
10+ const currentDay = today . getDate ( ) ;
11+
12+ // Calculate age
13+ let age = currentYear - birthYear ;
14+
15+ // Adjust if birthday hasn't happened yet this year
16+ if ( currentMonth < birthMonth || ( currentMonth === birthMonth && currentDay < birthDay ) ) {
17+ age -- ;
18+ }
19+
20+ console . log ( `You are ${ age } years old.` ) ;
21+
You can’t perform that action at this time.
0 commit comments