-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
24 lines (21 loc) · 938 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
fetch("./data.json")
.then(response => response.json())
.then(jsonData => init(jsonData));
function init(jsonData) {
const navItems = document.querySelectorAll('nav a');
const sections = document.querySelectorAll('article section');
navItems.forEach(navItem => {
navItem.addEventListener('click', () => {
document.getElementById("activePeriod").id = "";
navItem.id = "activePeriod";
let period = navItem.getAttribute('data-key');
// index from the JSON will correspond to the section index
jsonData.forEach((datum, i) => {
// set the `current` value
sections[i].querySelector("strong b").innerText = datum.timeframes[period].current;
// set the `previous` value
sections[i].querySelector("small b").innerText = datum.timeframes[period].previous;
})
});
});
}