File tree Expand file tree Collapse file tree 6 files changed +146
-0
lines changed Expand file tree Collapse file tree 6 files changed +146
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7
+ < link rel ="stylesheet " href ="style.css ">
8
+ < title > Age Calculator</ title >
9
+ </ head >
10
+ < body >
11
+ < div class ="container ">
12
+ < p id ="currDate "> </ p >
13
+ < p > Enter the DOB in format : (MM/DD/YYYY)</ p >
14
+ < input type ="text " placeholder ="Enter your D.O.B " id ="DOB ">
15
+ < button id ="CalcAge "> Age</ button >
16
+ </ div >
17
+ < div id ="displayAge ">
18
+ < p id ="age "> </ p >
19
+ </ div >
20
+ < script src ="script.js ">
21
+ </ script >
22
+ </ body >
23
+ </ html >
Original file line number Diff line number Diff line change
1
+
2
+ # Welcome 🖐 to the Age Calculator
3
+ It is a simple Javascript project which calculates our age in years.
4
+
5
+ ## Default view
6
+ ![ Default View] ( container.png )
7
+ ![ Default View] ( result.png )
8
+
9
+ ## 💻Tech Stack
10
+ <br >
11
+
12
+ ![ HTML] ( https://img.shields.io/badge/html5%20-%23E34F26.svg?&style=for-the-badge&logo=html5&logoColor=white )
13
+ ![ CSS] ( https://img.shields.io/badge/css3%20-%231572B6.svg?&style=for-the-badge&logo=css3&logoColor=white )
14
+ ![ JS] ( https://img.shields.io/badge/javascript%20-%23323330.svg?&style=for-the-badge&logo=javascript&logoColor=%23F7DF1E )
15
+
16
+ <br >
17
+
18
+ ### How to use:
19
+
20
+ ---
21
+
22
+ - Download or clone the repository
23
+
24
+ ```
25
+ git clone https://github.com/Ayushparikh-code/Web-dev-mini-projects.git
26
+ ```
27
+
28
+ - Go to the directory
29
+ - Run the index.html file
30
+ - Enter your DOB and find age..
31
+
32
+ <br >
33
+
34
+ ## Happy Coding!
Original file line number Diff line number Diff line change
1
+ let currDate = document . getElementById ( "currDate" ) ;
2
+ let dateOfBirth = document . querySelector ( "#DOB" ) ;
3
+ const CalcAge = document . getElementById ( "CalcAge" ) ;
4
+ const displayAge = document . getElementById ( "displayAge" ) ;
5
+ const Age = document . getElementById ( "age" ) ;
6
+ var today = new Date ( ) ;
7
+ currDate . innerText = `Today's Date is : ${ today . toLocaleDateString ( 'en-US' ) } ` ;
8
+
9
+ CalcAge . addEventListener ( "click" , ( ) => {
10
+ var birthDate = new Date ( dateOfBirth . value ) ;
11
+ var age = today . getFullYear ( ) - birthDate . getFullYear ( ) ;
12
+ var m = today . getMonth ( ) - birthDate . getMonth ( ) ;
13
+ if ( m < 0 || ( m === 0 && today . getDate ( ) < birthDate . getDate ( ) ) ) {
14
+ age = age - 1 ;
15
+ }
16
+ displayAge . style . visibility = "visible" ;
17
+ Age . innerText = `You are ${ age } years old.`
18
+ } ) ;
19
+
Original file line number Diff line number Diff line change
1
+ * {
2
+ margin : 0 ;
3
+ padding : 0 ;
4
+ box-sizing : border-box;
5
+ font-family : cursive;
6
+ }
7
+ .container {
8
+ display : flex;
9
+ width : 600px ;
10
+ margin : auto;
11
+ margin-top : 10% ;
12
+ margin-bottom : 10% ;
13
+ align-items : center;
14
+ justify-content : center;
15
+ flex-direction : column;
16
+ background-color : darkslateblue;
17
+ box-shadow : 8px 8px black;
18
+ color : white;
19
+ padding : 5% 0% ;
20
+ }
21
+ # currDate {
22
+ font-size : 40px ;
23
+ margin : 20px ;
24
+ font-weight : bold;
25
+ }
26
+ input {
27
+ font-size : 20px ;
28
+ padding : 15px ;
29
+ margin : 20px ;
30
+ text-align : center;
31
+ border-radius : 20px ;
32
+ border : 1px solid yellow;
33
+ cursor : pointer;
34
+ }
35
+ button {
36
+ font-size : 20px ;
37
+ padding : 10px 20px ;
38
+ border-radius : 10px ;
39
+ border : none;
40
+ background-color : yellow;
41
+ color : black;
42
+ margin : 20px ;
43
+ text-transform : uppercase;
44
+ font-weight : bold;
45
+ cursor : pointer;
46
+ }
47
+ button : hover {
48
+ background-color : white;
49
+ color : blue;
50
+ }
51
+
52
+ # displayAge {
53
+ display : flex;
54
+ align-items : center;
55
+ justify-content : center;
56
+ width : 620px ;
57
+ height : 480px ;
58
+ background-color : rgb (228 , 91 , 91 );
59
+ border-radius : 30px ;
60
+ position : absolute;
61
+ top : 19% ;
62
+ left : 30% ;
63
+ visibility : hidden;
64
+ }
65
+ # age {
66
+ color : white;
67
+ font-size : 50px ;
68
+ margin : 20px ;
69
+ font-weight : bold;
70
+ }
You can’t perform that action at this time.
0 commit comments