-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
43 lines (37 loc) · 1.07 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const subtitles = document.querySelectorAll(".previous");
const times = document.querySelectorAll(".time");
const listItems = document.querySelectorAll("li");
fetch("./data.json")
.then((res) => res.json())
.then((json) => {
const changeValues = (id) => {
let timefr = "";
switch (id) {
case "Day":
timefr = "daily";
break;
case "Week":
timefr = "weekly";
break;
case "Month":
timefr = "monthly";
break;
default:
break;
}
times.forEach((element, ind) => {
element.textContent = `${json[ind].timeframes[timefr].current}hrs`;
});
subtitles.forEach((element, ind) => {
element.textContent = `Last Day - ${json[ind].timeframes[timefr].previous}hrs`;
});
};
listItems.forEach((item) => {
item.addEventListener("click", () => {
listItems.forEach((item) => (item.className = ""));
item.className = "selected";
changeValues(item.id);
});
});
})
.catch((err) => console.log(err));