diff --git a/index.js b/index.js index ad3448c..078071c 100644 --- a/index.js +++ b/index.js @@ -17,13 +17,13 @@ const f = response.url.split('/').pop(); if (f === "metadata.json") { const metadata = await response.json(); - states = new Map(metadata.geo.map((c) => [c.uid, c.name])) + states = new Map(metadata.geo.map((c) => [c.uid, c.name])); parties = new Map(metadata.parties.map((c) => [c.code, c.name])); candidates = new Map(metadata.candidates.map((c) => [c.uid, [c.fullName, parties.get(c.candidateRaces[0].majorParty)]])); } else if (f === "president.json") { const president = await response.json(); - let data = president[0]["state_electionTypes"].map((t) => t.state.officeRaces[0].candidateVotes.map((o) => { + let data = president[0].state_electionTypes.map((t) => t.state.officeRaces[0].candidateVotes.map((o) => { return { "name": (candidates) ? candidates.get(o.candidate) : [o.candidate, "?"], "votes": o.totalVote @@ -40,7 +40,7 @@ return acc; }, []); - let stateVotes = president[0]["state_electionTypes"].map((t) => { + let stateVotes = president[0].state_electionTypes.map((t) => { return { "state": (states) ? states.get(t.state.uid) : t.uid, "current": t.state.officeRaces[0].officeVotes[0].totalVote, @@ -77,9 +77,15 @@ stateContainer.innerHTML = ''; stateVotes.forEach((row) => { const table = document.createElement('table'); + const caption = document.createElement('caption'); + caption.innerHTML = ` +