Skip to content

Commit

Permalink
new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
solangeihirwe03 committed Mar 13, 2024
1 parent c59fbf6 commit 1937173
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions age.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ body{
font-size: 15px;
border-radius: 8px;
}
.display{
padding: 5px 0;
font: 20px;
font-size: 20px;
}
14 changes: 13 additions & 1 deletion age.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
const date = document.getElementById('date');
const date = document.getElementById('date');
let btn = document.getElementById('btn')
let dob = new Date();
let display = document.querySelector('.display');
btn.addEventListener('click', (e)=>{
e.preventDefault();
const enteredDate = date.value;
let currentYear = dob.getFullYear();
let dateOfBirth = new Date(enteredDate);
let getYear = dateOfBirth.getFullYear();
let age = currentYear - getYear;
display.textContent = `Your age is ${age} years old`
})
5 changes: 3 additions & 2 deletions ageCalculator.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ <h2>Age Calculator</h2>
<div class="dob">
<h2>Enter your date of birth</h2>
<input type="date" name="date" id="date">
<button>Calculate Age</button>
<button id="btn">Calculate Age</button>
</div>
<div class="display"></div>
<div class="display" id="display"></div>
</div>
<script src="./age.js"></script>
</body>
</html>

0 comments on commit 1937173

Please sign in to comment.