File tree Expand file tree Collapse file tree 1 file changed +44
-6
lines changed
Expand file tree Collapse file tree 1 file changed +44
-6
lines changed Original file line number Diff line number Diff line change 1414 # age {
1515 margin : auto;
1616 width : 50% ;
17- height : 300 px ;
17+ height : max-content ;
1818 border : var (--main-color ) 2px solid;
1919 border-radius : 10px ;
2020 display : flex;
2424 margin-top : 20% ;
2525 background-image : linear-gradient (45deg , # 58dbb4 10% , # 138f13 100% );
2626
27+
28+ }
29+ form {
30+ display : flex;
31+ flex-direction : column;
32+ align-items : center;
33+ justify-content : center;
34+ margin-top : 20px ;
35+ margin-bottom : 20px ;
2736 }
2837 input {
2938 margin : 10px ;
5059 height : 45px ;
5160 font-size : 1rem ;
5261 }
62+ # result {
63+ margin-bottom : 20px ;
64+ display : none;
65+ }
5366 </ style >
5467</ head >
5568< body >
56- < div id ="age ">
69+ < div id ="age ">
70+ < h1 > Welcome to Age Calculator</ h1 >
71+ < p > Please enter your year of birth:</ p >
72+ < form id ="ageForm ">
73+
5774
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 >
75+ < label for ="yearOfBirth "> Year of Birth:</ label >
76+ < input type ="number " id ="yearOfBirth " min ="1980 " max ="2025 " required >
77+
78+ < button id ="btn " type ="submit "> Calculate</ button >
79+ </ form >
80+ < div id ="result ">
81+ < h2 > Your Age is: < span id ="ageDisplay "> </ span > </ h2 >
82+
83+ </ div >
6284</ div >
85+
86+
87+ < script >
88+ const btn = document . getElementById ( "btn" ) ;
89+ const form = document . getElementById ( "ageForm" ) ;
90+
91+ form . addEventListener ( "submit" , function ( event ) {
92+ event . preventDefault ( ) ;
93+ const yearOfBirth = document . getElementById ( "yearOfBirth" ) . value ;
94+ const currentYear = new Date ( ) . getFullYear ( ) ;
95+ const age = currentYear - yearOfBirth ;
96+ document . getElementById ( "result" ) . style . display = "block" ;
97+ document . getElementById ( "ageDisplay" ) . textContent = `${ age } years old` ;
98+ } ) ;
99+
100+ </ script >
63101</ body >
You can’t perform that action at this time.
0 commit comments