-
Notifications
You must be signed in to change notification settings - Fork 131
/
app.js
39 lines (32 loc) · 1.02 KB
/
app.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
30
31
32
33
34
35
36
37
38
39
const dropdown = document.getElementById("tech-dropdown");
const techList = document.getElementById("rows");
dropdown.addEventListener("input", function(e) {
const searchTerm = e.target.value.trim();
Array.from(techList.getElementsByTagName("p")).forEach((element) => {
if (
searchTerm === "" ||
element.dataset.name.toLowerCase().includes(searchTerm.toLowerCase())
) {
element.style.display = "block";
} else {
element.style.display = "none";
}
});
});
const dateFieldList = document.getElementsByClassName("date-field");
Array.from(dateFieldList).forEach((dateField) => {
const today = new Date();
const then = new Date(dateField.dataset.date);
var ageDifMs = today - then;
var ageDate = new Date(ageDifMs);
const yearsOld = Math.abs(ageDate.getUTCFullYear() - 1970);
let text = "";
if (yearsOld === 0) {
text = "hardly any time at all!";
} else if (yearsOld === 1) {
text = "1 year";
} else {
text = `${yearsOld} years`;
}
dateField.innerText = text;
});