-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (52 loc) · 1.47 KB
/
script.js
File metadata and controls
56 lines (52 loc) · 1.47 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
const btn = document.querySelectorAll("#btn");
const currentHours = document.querySelectorAll("#current");
const previousHours = document.querySelectorAll("#previous");
// daily data
function dailyData() {
fetch("./data.json")
.then((res) => res.json())
.then((data) =>
currentHours.forEach((e, i) => {
currentHours[i].textContent = `${data[i].timeframes.daily.current}hrs`;
previousHours[
i
].textContent = `Last week - ${data[i].timeframes.daily.previous}hrs`;
})
);
}
// weekly data
function weeklyData() {
fetch("./data.json")
.then((res) => res.json())
.then((data) =>
currentHours.forEach((e, i) => {
currentHours[i].textContent = `${data[i].timeframes.weekly.current}hrs`;
previousHours[
i
].textContent = `Last week - ${data[i].timeframes.weekly.previous}hrs`;
})
);
}
// monthly data
function monthlyData() {
fetch("./data.json")
.then((res) => res.json())
.then((data) =>
currentHours.forEach((e, i) => {
currentHours[
i
].textContent = `${data[i].timeframes.monthly.current}hrs`;
previousHours[
i
].textContent = `Last week - ${data[i].timeframes.monthly.previous}hrs`;
})
);
}
// active
btn.forEach((butt) => {
butt.addEventListener("click", function (e) {
e.preventDefault();
btn.forEach((b) => b.classList.remove("text-white"));
this.classList.add("text-white");
});
});