Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculator #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ This repository contains a collection of frontend projects.Each project is built
<td>Bubble Game</td>
<td><a href="./project-20_bubble_game">Click Here</a></td>
</tr>
<tr>
<td>21</td>
<td>Bubble Game</td>
<td><a href="./project-21_age_calculator/index.html">Click Here</a></td>
</tr>
</table>


Expand Down
Binary file added project-21_age_calculator/age-calc-for-index.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions project-21_age_calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
<title>Age Calculator</title>
</head>
<body>
<main>
<h1>Age Calculator</h1>
<form >
<label for="date_of_birth">Enter your date of birth</label>
<input type="date" name="date_of_birth" id="date_of_birth">
<button type="submit">Calculate Age</button>
</form>
<p id="show_age">Your age is 21 years old</p>
</main>
<script src="./script.js"></script>
</body>
</html>
39 changes: 39 additions & 0 deletions project-21_age_calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
let button = document.querySelector("button");
let showAge = document.getElementById("show_age");
let dateOfBirth = document.querySelector("input");
button.addEventListener("click",(e)=>{
e.preventDefault();
const today = new Date();
const dob = new Date(dateOfBirth.value)
let age = today.getFullYear() - dob.getFullYear();
const month = today.getMonth() - dob.getMonth();
const date = today.getDate() - dob.getDate();

if(dateOfBirth.value =="")
alert("Please enter your birthday");

else {

if(today.getMonth() < dob.getMonth() || today.getDate() < dob.getDate()){
age--;

showAge.innerText = `Your age is ${age} years old`

}



else {

if(today.getMonth() > dob.getMonth() || today.getDate() > dob.getDate()){
age--;
}

showAge.innerText = `Your age is ${-age} years old`

}

}


})
63 changes: 63 additions & 0 deletions project-21_age_calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}

body{
width:100%;
height:100vh;
background-color: #f7f7f7;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}

h1 {
font-size: 220%;
}

main{
background-color: #ffffff;
width:43.5%;
height: 38%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 4.5% auto;
border-radius: 0.5rem;
/* border: solid 2px red; */
gap: 1.5rem;
padding: 2rem;
box-shadow: 0px 0px 6px 3px #dcdada;
}

form{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0.5rem;
width:100%
}

form input{
width:50%;
padding:0.4rem;
border-radius: 0.3rem;
border: 1px rgb(205, 204, 204) solid;
}

form button{
color: white;
background-color: #007bff;
padding: 0.5rem;
border-radius: 0.3rem;
border: none;
width:20%;
}

#show_age{
/* font-size: 1.5rem; */
font-size: 150%;
}
5 changes: 4 additions & 1 deletion sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<url>
<loc>https://armanidrisi.github.io/frontend-projects/</loc>
</url>
<url>
<loc>https://shivambansal96.github.io/ageCalculator/</loc>
</url>
<url>
<loc>https://armanidrisi.github.io/frontend-projects/project-18_toggle_dark_light_mode</loc>
</url>
Expand Down Expand Up @@ -56,5 +59,5 @@
</url>
<url>
<loc>https://armanidrisi.github.io/frontend-projects/project-1_landing-page</loc>
</url>
</url>
</urlset>