forked from HackYourFuture/Assignments
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathex5-vscDebug.js
More file actions
37 lines (30 loc) · 1.09 KB
/
ex5-vscDebug.js
File metadata and controls
37 lines (30 loc) · 1.09 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
/*------------------------------------------------------------------------------
Full description at: https://github.com/HackYourFuture/Assignments/blob/main/3-UsingAPIs/Week2/README.md#exercise-5-using-the-vscode-debugger
Use the VSCode Debugger to fix the bugs
--------------------------------------------------------------- --------------*/
async function getData(url) {
const response = await fetch(url);
return response.json();
}
function renderLaureate({ knownName, birth, death }) {
console.log(`\nName: ${knownName.en}`);
console.log(`Birth: ${birth.date}, ${birth.place.locationString}`);
if (death) {
console.log(`Death: ${death.date}, ${death.place.locationString}`);
}
}
function renderLaureates(laureates) {
laureates.forEach(renderLaureate);
}
async function fetchAndRender() {
try {
const { laureates } = await getData(
'https://api.nobelprize.org/2.0/laureates?birthCountry=Netherlands&format=json&csvLang=en'
);
renderLaureates(laureates);
renderLaureates(laureates);
} catch (err) {
console.error(`Something went wrong: ${err.message}`);
}
}
fetchAndRender();