-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js~
31 lines (25 loc) · 865 Bytes
/
index.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
const submit = document.querySelector('#submit');
const input = document.querySelector('#input');
const responseField = document.querySelector('#responseField');
async function processData() {
const response = await fetch('CovidData/covid-data.json')
let jsonResponse = await response.json();
let county = input.value;
if (response.ok) {
renderResponse(jsonResponse, county);
} else {
renderError(response.status);
}
}
function renderResponse(response, county) {
let c = response[county];
responseField.innerHTML = `<p>County: ${county}<br>Week: ${response[county].week}<br>Cases: ${response[county].cases}`;
}
function renderError(error) {
responseField.innerHTML = "<p>Error: ${error}<p>";
}
const displayData = event => {
event.preventDefault();
processData();
}
submit.addEventListener('click', displayData);