forked from jeff-mccommas/Tandem-Seven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
31 lines (29 loc) · 764 Bytes
/
scripts.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
/**
* Created by jmccommas on 12/12/17 7:57 PM*/
function createNode(element) {
return document.createElement(element);
}
function append(parent, el) {
return parent.appendChild(el);
}
const flights = {
fleight: 'flight_number'
}
/// created a fetch function to map data
const ul = document.getElementById('flights');
const url = 'https://api.spacexdata.com/v2/launches';
fetch(url)
.then((resp) => resp.json())
.then(function (data) {
let flights = data.results;
return flights.map(function (flight) {
let ul = createNode('ul'),
span = createNode('span');
span.innerHTML = `${flight.fleight_number} ${flight.launch_year}`;
append(li, span);
append(ul, li);
})
})
.catch(function (error) {
console.log(JSON.stringify(error));
});