Skip to content
Merged
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
22 changes: 22 additions & 0 deletions web/pages/Himanshu1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Age Calculators</title>
<link rel="stylesheet" href="Himanshu1.css">
</head>
<body>
<div class="container">
<div class="calculator">
<h1>JavaScript<br><span> Age Calculator</span></h1>
<div class="input-box">
<input type="date" id="date">
<button onclick="calculateAge()">Calculate</button>
</div>
<p id="result"></p>
</div>
</div>
<script src="Himanshu1.js"></script>
</body>
</html>
46 changes: 46 additions & 0 deletions web/scripts/Himanshu1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
let userInput = document.getElementById("date");
userInput.max = new Date().toISOString().split("T")[0];
let result = document.getElementById("result");

function calculateAge(){
let birthDate = new Date(userInput.value);

let d1 = birthDate.getDate();
let m1 = birthDate.getMonth() + 1;
let y1 = birthDate.getFullYear();

let today = new Date();

let d2 = today.getDate();
let m2 = today.getMonth() + 1;
let y2 = today.getFullYear();

let d3, m3, y3;

y3 = y2-y1;

if(m2 >= m1){
m3 = m2 - m1;
}else{
y3--;
m3 = 12 + m2 - m1;
}

if(d2 >=d1){
d3 = d2 - d1;
}else{
m3--;
d3 = getDaysInMonth(y1,m1) + d2 - d1;
}
if(m3 < 0){
m3 = 11;
y3--;
}
result.innerHTML = `You are <span>${y3}</span> years, <span>${m3}</span> months, and <span>${d3}</span> days old.`;


}

function getDaysInMonth(year, month){
return new Date(year, month, 0).getDate();
}
81 changes: 81 additions & 0 deletions web/stylesheet/Himanshu1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}

.container{
width: 100%;
min-height: 100vh;
background: linear-gradient(135deg, #4203a9, #90bafc);
color: #fff;
padding: 10px;
}

.calculator{
width: 100%;
max-width: 600px;
margin-left: 10%;
margin-top: 10%;
}

.calculator h1{
font-size: 60px;
}

.calculator h1 span{
color: #ffff76;
}

.input-box{
margin: 40px 0;
padding: 35px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.3);
display: flex;
align-items: center;
}

.input-box input{
flex: 1;
margin-right: 20px;
padding: 14px 20px;
border: 0;
outline: 0;
font-size: 18px;
border-radius: 5px;
position: relative;
}

.input-box button{
background: #ffff76;
border: 0;
outline: 0;
padding: 15px 30px;
border-radius: 5px;
font-weight: 600;
color: #333;
cursor: pointer;
}

.input-box input::-webkit-calendar-picker-indicator{
top: 0;
left: 0;
right: 0;
bottom: 0;
width: auto;
height: auto;
position: absolute;
background-position: calc(100% - 10px);
background-size: 30px;
cursor: pointer;
}

#result{
font-size: 20px;
}

#result span{
color: #ffff76;
}
Loading