-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
47 lines (40 loc) · 1.01 KB
/
script.js
File metadata and controls
47 lines (40 loc) · 1.01 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
const APOD_URL = "https://api.nasa.gov/planetary/apod?api_key=q5CY83py5gbzhu1pMa82D3zvNQOy6cwlEwXBzHMH"
// I, II
// async function fetchApod(url){
// const response = await fetch(url);
// if(response.ok){
// return await response.json();
// } else {
// throw new Error("error message");
// }
// }
// III.
function fetchApod(url){
return fetch(url).then((response) => {
if(response.ok){
return response.json();
} else {
throw new Error("error message");
}
})
}
async function main(){
// I.
// try {
// const data = await fetchApod(APOD_URL);
// console.log(data);
// } catch (error) {
// console.log(error);
// }
// II.
// fetchApod(APOD_URL)
// .then((data) => {
// console.log(data);
// })
// .catch((error) => {
// console.log(error);
// })
// III.
fetchApod(APOD_URL).then(data => console.log(data)).catch(error => console.log(error));
}
main();