+ 2
data is a JSON object. Its contents are accessed using dot notation. So
data.explanation
accesses the data in the explanation field of the JSON object.
+ 2
JSON is a format for saving data. It's very simple and very popular. You should take a look at it.
+ 2
The call to the API fetches a JSON object. This is often the case for data APIs. This object is then assigned to the data variable for further manipulation.
https://www.digitalocean.com/community/tutorials/how-to-work-with-json-in-javascript
+ 1
In the code three fields of the JSON object are accessed: explanation, title, and url.
+ 1
So the JSON object looks probably something like this:
{"explanation": "some text",
"title": "some text",
"url": "an image url"}
0
You can see the full JSON file here:
https://api.nasa.gov/planetary/apod?api_key=XA6IuMbstRjVQf0EFkp2cdhQPOB4QuLhsMZUu4B5
0
That's lines 27-28. With the API's url in line 23.
0
You're welcome.
0
They used the .json() method instead:
https://developer.mozilla.org/en-US/docs/Web/API/Response/json