forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (68 loc) · 2.06 KB
/
index.js
File metadata and controls
80 lines (68 loc) · 2.06 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const games = document.querySelector('.games');
const url = "http://gd2.mlb.com/components/game/mlb/year_2017/postseason_scoreboard.json"
function createNode(element) {
return document.createElement(element);
}
function append(parent, child) {
return parent.appendChild(child);
}
fetch(url)
.then((resp) => resp.json())
.then((data) => {
const game_data = data.games;
return game_data.map((game) => {
console.log(game);
let game_container = createNode('div')
let home_team = createNode('div')
let home_score = createNode('p')
let away_team = createNode('div')
let away_score = createNode('p')
game_container.classList.add('game');
home_team.classList.add('team');
away_team.classList.add('team');
home_team.innerHTML = `${game.home_team_city} ${game.home_team_name}`
home_score.innerHTML = `${game.linescore.r.home}`
console.log(game.linescore.r.home);
away_score.innerHTML = `${game.linescore.r.away}`
away_team.innerHTML = `${game.away_team_city} ${game.away_team_name}`
append(game_container, home_team);
append(home_team, home_score);
append(game_container, away_team);
append(away_team, away_score);
append(games, game_container);
})
})
.catch((err) => {
console.log(err)
});
console.log("LOADED");
// //const url = 'https://randomuser.me/api';
// // The data we are going to send in our request
// let data = {
// name: 'Sara'
// }
// // The parameters we are gonna pass to the fetch function
// let fetchData = {
// method: 'POST',
// body: data,
// headers: new Headers()
// }
// fetch(url, fetchData)
// .then(function() {
// // Handle response you get from the server
// });
// const url = 'https://randomuser.me/api';
// // The data we are going to send in our request
// let data = {
// name: 'Sara'
// }
// // Create our request constructor with all the parameters we need
// var request = new Request(url, {
// method: 'POST',
// body: data,
// headers: new Headers()
// });
// fetch(request)
// .then(function() {
// // Handle response we get from the API
// })