-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (26 loc) · 915 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const yearInput = document.getElementById("yearOfBirth");
const currentYear = new Date().getFullYear();
const ageDisplay = document.getElementById("ageResults");
const textBoard = document.getElementById("textBoard");
yearInput.addEventListener("keyup", function (event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("submit").click();
}
});
function ageCounter() {
let yearOfBirth = parseInt(yearInput.value);
let ageResults = currentYear - yearOfBirth;
if (yearOfBirth) {
ageDisplay.innerHTML = ageResults + " Years";
textBoard.innerHTML = "Your Age Is";
if (ageResults == 1) {
ageDisplay.innerHTML = ageResults + " Year";
textBoard.innerHTML = "Your Age Is";
} else if (ageResults <= 0) {
ageDisplay.innerHTML = "";
textBoard.innerHTML = "No results";
}
document.getElementById("yearOfBirth").value = "";
}
}